Please I need help! I have a php file that works properly before I attempt to add a picture to the categories. It is a photo album page that displays the categories in the mysql database. Then you select the category to see the pictures. Now I need to have one picture from each category inserted above the category name. How can I do that from this php? The RED sections are what I added after it was working fine without pictures. The RED indicates what I’m trying to do to make it work and I think I’m WAY off. I have 2 tables, gallery_category (which has category_id and category_name) and gallery_photos (which has photo_id, photo_filename, photo_caption, and photo_category). Thanks for helping. Please let me know if you need any further information.
[php]
<?php
include("config2.php");
$result_array = array();
$counter = 0;
$cid = (int)($_GET['cid']);
$pid = (int)($_GET['pid']);
// Category Listing
if( empty($cid) && empty($pid) )
{
$number_of_categories_in_row = 3;
$result = mysql_query( "SELECT c.category_id,c.category_name,COUNT(photo_id),p.photo_filename
FROM gallery_photos as p, gallery_category as c
LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
GROUP BY c.category_id" );
while( $row = mysql_fetch_array( $result ) )
{
$result_array[] = "
".$row[1]." "."(".$row[2]." photos)";
}
mysql_free_result( $result );
$result_final = "
\n";
foreach($result_array as $category_link)
{
if($counter == $number_of_categories_in_row)
{
$counter = 1;
$result_final .= "\n
\n
\n";
}
else
$counter++;
$result_final .= "\t".$category_link." | \n";
}
if($counter)
{
if($number_of_categories_in_row-$counter)
$result_final .= "\t | \n";
$result_final .= "
";
}
}
// Thumbnail Listing
else if( $cid && empty( $pid ) )
{
$number_of_thumbs_in_row = 4;
$result = mysql_query( "SELECT photo_id,photo_caption,photo_filename FROM gallery_photos WHERE photo_category='".addslashes($cid)."'" );
$nr = mysql_num_rows( $result );
if( empty( $nr ) )
{
$result_final = "\t
No Photos found |
\n";
}
else
{
while( $row = mysql_fetch_array( $result ) )
{
$result_array[] = "
![".$row[1]."]()
";
}
mysql_free_result( $result );
$result_final = "
\n";
foreach($result_array as $thumbnail_link)
{
if($counter == $number_of_thumbs_in_row)
{
$counter = 1;
$result_final .= "\n
\n
\n";
}
else
$counter++;
$result_final .= "\t".$thumbnail_link." | \n";
}
if($counter)
{
if($number_of_photos_in_row-$counter)
$result_final .= "\t | \n";
$result_final .= "
";
}
}
}
// Full Size View of Photo
else if( $pid )
{
$result = mysql_query( "SELECT photo_caption,photo_filename FROM gallery_photos WHERE photo_id='".addslashes($pid)."'" );
list($photo_caption, $photo_filename) = mysql_fetch_array( $result );
$nr = mysql_num_rows( $result );
mysql_free_result( $result );
if( empty( $nr ) )
{
$result_final = "\t
No Photo found |
\n";
}
else
{
$result = mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes($cid)."'" );
list($category_name) = mysql_fetch_array( $result );
mysql_free_result( $result );
$result_final .= "
\n\t
Categories >
$category_name
| \n
\n";
$result_final .= "
\n\t
$photo_caption
|
";
}
}
// Final Output
echo <<<__HTML_END
Pixi Photography | Photo Gallery
__HTML_END;
?>[/php]