Cyberpunk Wannabe
Gender:
Posts: 35
234 credits Members referred : 0
If at first you dont suceed, try try again
« on: Apr 10, 2007, 01:13:18 AM »
Hello!
I am trying to a build a CMS for my first big php project, I have had a lot of difficulty with adding images but finaally got something along with dynamic text built using dream weaver.
I have built it so that the image is a separate table from the text, but i would like the images to be set to the primary key of the text table, so they display together.
<?php #--------------------------------------------------# #DISPLAY IMAGES AND INFORMATION #--------------------------------------------------# $table = 'image'; $sql = "SELECT * FROM ".$table." ORDER BY 'image_id'"; $result = mysql_query ($sql, $conn_addnews); $i=0; $str='';
if (mysql_num_rows($result)>0) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { #THIS VARIABLE IS AN ARRAY THAT HOLDS THE SIZE PROPERTIES OF THE IMAGE... USED TO GET THE DIMENSIONS $size = getimagesize("http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?act=view&iid=".$row["image_id"]);
im thinking some thing like this but i dunno.. $master_id = "SELECT 'image_id' FROM 'add_news'" $sql = "SELECT * FROM ".$table." ORDER BY '$master_id'";
« Last Edit: Apr 10, 2007, 02:34:39 AM by jaffa »
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6309
38674 credits Members referred : 374
It's time to use PHP5!
« Reply #1 on: Apr 10, 2007, 08:05:16 AM »
why do you store the image name in a second table?
Cyberpunk Wannabe
Gender:
Posts: 35
234 credits Members referred : 0
If at first you dont suceed, try try again
« Reply #4 on: Apr 10, 2007, 09:23:36 PM »
i have it so the text table and image table are using an identical primary key which is image_id in an attempt to link them...i admit i dont really know what im doing here..i need a shove in the right direction.
Yeah, i would like to add a feature of uploading multible files later, and also mp3's..
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 8037
41179 credits Members referred : 3
« Reply #5 on: Apr 10, 2007, 09:41:30 PM »
The right logic on this is the opposite. I mean you should have a primary key in the content table, which will use to link to the table of images. This way you can have more than one images to each listing.
But still I am not sure where you are stucked with this....
Cyberpunk Wannabe
Gender:
Posts: 35
234 credits Members referred : 0
If at first you dont suceed, try try again
« Reply #6 on: Apr 10, 2007, 10:08:15 PM »
right ok, is it cool to ask if u could write a bit of pseudo code on this,
something like this? $master_id = "SELECT 'image_id' FROM 'textcontent_table" $result = "SELECT * FROM ".imagetable" ORDER BY '$master_id'";....?
my brain is fryed over this, time for a guiness
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 8037
41179 credits Members referred : 3
« Reply #7 on: Apr 10, 2007, 10:14:16 PM »
Ok, here is an example :
$master_id = "SELECT 'id' FROM 'textcontent_table";// <- This is the unique id of your content page $result = "SELECT * FROM "imagetable" WHERE contentID = '$master_id'";....?
So you will need two tables with a structure like this :
textcontent_table id, etc. id in this table is primary key
imagetable id, contentID, etc.
id here is primary key and contentID is index. In the contentID you will store the id of the content page that this photo is displayed.
</tr> <tr> <td>image</td> <td><?php #--------------------------------------------------# #DISPLAY IMAGES AND INFORMATION #--------------------------------------------------
$sql = "SELECT * FROM image WHERE image_id = $recordID"; $result = mysql_query ($sql, $conn_addnews); $i=0; $str='';
if (mysql_num_rows($result)>0) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { #THIS VARIABLE IS AN ARRAY THAT HOLDS THE SIZE PROPERTIES OF THE IMAGE... USED TO GET THE DIMENSIONS $size = getimagesize("http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?act=view&iid=".$row["image_id"]);