Hi i have developed a photo gallery in php and now i want to add comment section to those photos in the gallery.Actually i have table to store the comments regarding the particular image.I'm able to retrive the recent comments for the image,but the problem here is i'm not getting the previous comments posted by users for the same image.I'm getting the comments of all the photos into an array using image id which links to the id of the image in another table like

img_id comment
------- --------
1 nice picture
1 super picture
1 awesome picture


id file_name
--- ----------
1 flower.jpg


in this case i'm able to retrive only the last comment i.e., "awesome picture". but i want to get all the comments displayed for the same picture. Any help...!

it's like this

$images=array();
for($i=0; $i<count;$i++){
$query="select * from table1 where img_id=(select id from table2 where filename="")";
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
/*here i'm getting the results from tht table1 to an array but now how to get them out from the array accroding to img_id*/
}
}

did you try to echo youre query?
can you post the column of table1?

Are you trying to get all comments for one filename? If so, do you have the filename in a variable? Then you can do something like this:

$filename = 'flower.jpg';
$query = "SELECT * FROM table1 t1, table2 t2 WHERE t1.id=t2.img_id AND t1.file_name='$filename'";
$result = mysql_query($query);
if ($result) {
  while ($row = mysql_fetch_array($result)) {
    echo $row['comment'] . '<br/>';
  }
}
else {
  // no comments
}

yeah the query is working fine and i'm getting the comment for the image but that is only recent one,i want the previous comments for the same image to be displayed which are stored in the database...!

Finally see the problem:

select * from table1 where img_id in (select id from table2 where filename='...')

Use IN instead of =

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.