Jump to content

Image gallery using php and mySQL.


ingve

Recommended Posts

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  ;D

Link to comment
https://forums.phpfreaks.com/topic/113797-image-gallery-using-php-and-mysql/
Share on other sites

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'];
   }
}

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.