Sure, I can take a peek at it if you would like.
I think what you are wanting is a page that will have a list of links to photo categories that when clicked will show a list of all photos in that category. The catch is you don't want to have to manually add a link for new categories. Is that right?
Then I think the best solution for you would be to create another table to store your categories something like:
`id` | `category_name`
------------------
1 | South Dakota
2 | Illinois
3 | Wyoming
Convert the 'category' field in your current image table from VARCHAR() to INT(), and use the category ID instead.
Now, you can query the category table to build your links:
PHP Code:
$sql .= "SELECT `category_name` FROM `category` ORDER BY `id` ASC";
$query = mysql_query( $sql );
if( mysql_num_rows( $query ) > 0 ){
while( $row = mysql_fetch_assoc( $query ) ){
echo '<a href="page.php?group=' . $row[ 'id' ] . '">' . $row[ 'category' ] . '</a>';
}
}
This should produce links like so:
<a href="page.php?group=1">South Dakota</a>
<a href="page.php?group=2">Illinois</a>
<a href="page.php?group=3">Wyoming</a>
Now, here you have 2 options. You can do a simple query to poll only the data in the image table or you can use a more complex query to select data from both image and category tables.
For the first option, the sql you have now should do the trick, just need to change the echo statement to show images instead of links:
PHP Code:
$sql = "SELECT * FROM `images` WHERE `category`='" . $_GET[ 'group' ] . "'";
$query = mysql_query( $sql );
if( mysql_num_rows( $query ) > 0 ){
while( $row = mysql_fetch_assoc( $query ) ){
echo '<img src="' . $row[ 'img_path' ] . '" alt="">';
}
}else{
echo "Sorry no images found for that category!";
}
For the second option to include the category info in the image query, do a simple join like so:
PHP Code:
$sql = "SELECT * FROM `category`,`images` WHERE `images`.`category`=`category`.`id` AND `images`.`category`='" . $_GET[ 'group' ] . "'";
$query = mysql_query( $sql );
if( mysql_num_rows( $query ) > 0 ){
while( $row = mysql_fetch_assoc( $query ) ){
echo '<img src="' . $row[ 'img_path' ] . '" alt="' . $row[ 'category' ] . '">';
}
}else{
echo "Sorry no images found for that category!";
}
Take a look at this page and see if it is doing what you want your page to do:
http://scarecrowe.com/gallery/gallery.php
If you are wanting auto-creation of links for categories, I think the second table to store the category info is the way to go.
crazy8, Check your PMs.....