ingve Posted July 8, 2008 Share Posted July 8, 2008 I am trying to build an image gallery using php and mySQL. I use one table containing the image info and the image title, called IMG, where filepath and title is stored, and another table containing just the title. I want the images with the same title to be displayed with the common title displayed first, and all the images with the same title underneath the title like this: TITLE ________________________ Image1, image 2 etc... This is what I have so far.. $query = "select img.title, img.img from img inner join imgtitle on img.title=imgtitle.title where imgtitle.title='snow'"; $feedback = mysql_query($query, $connect); while($img = mysql_fetch_array($feedback)) { $title = $img["title"]; $img = $img["img"]; echo $title; echo "<br>"; echo $img; } So, if 2 or more images has the same title, the title should be displayed only once, so that it looks like a group.. An example can be viewed here: http://www.bully-music.com/main.php?menu=media&media=images Thanks in advance! I hope someone can help me Link to comment https://forums.phpfreaks.com/topic/113797-image-gallery-using-php-and-mysql/ Share on other sites More sharing options...
lemmin Posted July 8, 2008 Share Posted July 8, 2008 Loop through the titles and check if they are the same: $lastTitle = ''; while($img = mysql_fetch_array($feedback)) { if ($img['title'] == $lastTitle) //Echo image only else { //echo title and image; $lastTitle = $img['title']; } } Link to comment https://forums.phpfreaks.com/topic/113797-image-gallery-using-php-and-mysql/#findComment-584786 Share on other sites More sharing options...
cooldude832 Posted July 8, 2008 Share Posted July 8, 2008 are you using word "title' such as a category? If you want to group all them under a title te way to do that is to query from your table and order by the field you wish to group by then in your loop you do someting like <?php $cat = ""; while($row = mysql_fetch_assoc($r)){ if($cat != $row['SORTCAT/TITLE']){ echo "<br /><H1>".$row['SORTCAT'].'</h1><br /><br />"; } $cat = $row['SORTCAT/TITILE']; #echo out the data as normal here } ?> Make sense Link to comment https://forums.phpfreaks.com/topic/113797-image-gallery-using-php-and-mysql/#findComment-584789 Share on other sites More sharing options...
ingve Posted July 11, 2008 Author Share Posted July 11, 2008 Thanks a million, lemmin. Worked like a charm. ;D Link to comment https://forums.phpfreaks.com/topic/113797-image-gallery-using-php-and-mysql/#findComment-587416 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.