Hi all,
I have been struggling to figure out what went wrong and/or mistake I made with my website practice.
I incorporated the Image Gallery with my website practice and so far most of the function show correct except with viewing a gallery. Once I select the category to see the content then boom it says no image, but actually there is. See the attachment please.
here is my index:
<div id="content">
<div>
<?php
if (empty($_GET['cat']) )
{ $cat = '/'; }
else
{ $cat = ($_GET['cat']); }
if ( empty($_GET['page']) )
{ $page = 'about'; }
else
{ $page = preg_replace('/[^a-zA-Z0-9]/', '', $_GET['page']); }
if ( file_exists($cat . '/' . $page . '.php') )
{ include $cat . '/' . $page . '.php'; }
else
{ include 'info/error.inc.php'; }
?>
</div>
</div>
and this is my viewgalery (i rename it to main):
<?php
include("config.inc.php");
// initialization
$result_array = array();
$counter = 0;
// $cid = (int)($_GET['cid']); // <--commented
// $pid = (int)($_GET['pid']); // <--commented
// replaced the above codes
if (isset($_GET['cid'])) { $cid = (int)($_GET['cid']); }
if (isset($_GET['pid'])) { $pid = (int)($_GET['pid']); }
// Category Listing
if( empty($cid) && empty($pid) )
{
$number_of_categories_in_row = 4;
$result = mysql_query( "SELECT c.category_id,c.category_name,COUNT(photo_id)
FROM 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[] = "<a href='index.php?cat=spgallery&page=main&cid=".$row[0]."'>".$row[1]."</a> "."(".$row[2].")";
}
mysql_free_result( $result );
$result_final = "<tr>\
";
foreach($result_array as $category_link)
{
if($counter == $number_of_categories_in_row)
{
$counter = 1;
$result_final .= "\
</tr>\
<tr>\
";
}
else
$counter++;
$result_final .= "\ <td>".$category_link."</td>\
";
}
if($counter)
{
if($number_of_categories_in_row-$counter)
$result_final .= "</tr>";
}
}
// Thumbnail Listing
else if( $cid && empty( $pid ) )
{
$number_of_thumbs_in_row = 4;
// If current page number, use it
// if not, set one!
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results = 8;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
$result = @mysql_query( "SELECT photo_id,photo_caption,photo_filename FROM gallery_photos WHERE photo_category='".addslashes($cid)."' LIMIT $from, $max_results");
$nr = @mysql_num_rows( $result );
if( empty( $nr ) )
{
$result_final = "\ <tr><td><div align=\\"center\\"><strong>No images in category found!</strong>
<br><br><font size=\\"2\\"><a href='index.php?cat=spgallery&page=main'>Back to Photo Gallery Category List</a></font>
</div></td></tr>\
";
}
else
{
while( $row = mysql_fetch_array( $result ) )
{
$result_array[] = "<a href='index.php?cat=spgallery&page=main&cid=$cid&pid=".$row[0]."'><img src='".$images_dir."/tb_".$row[2]."' border='0' alt='".$row[1]."' /></a>";
}
mysql_free_result( $result );
$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 = "<tr><a href='index.php?cat=spgallery&page=main'>Categories</a> > $category_name<br><br>";
foreach($result_array as $thumbnail_link)
{
if($counter == $number_of_thumbs_in_row)
{
$counter = 1;
$result_final .= $category_link."\
</tr>\
<tr>\
";
}
else
$counter++;
$result_final .= "\ <td><div align=\\"center\\">".$thumbnail_link."</div></td>\
";
}
if($counter)
{
if($number_of_photos_in_row)
$result_final .= "\ <td colspan='".($number_of_thumbs_in_row)."'></td>\
";
$result_final .= "</tr>\
";
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM gallery_photos WHERE photo_category=".addslashes($cid).""),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
if ($total_pages >1)
{ // build links if more than one page
// Build Page Number Hyperlinks
$result_final .= "<tr><td colspan='".$number_of_thumbs_in_row."'>Showing Page: ".$page.' of '.$total_pages."<br>";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
$result_final .= "\
<a href=\\"".$_SERVER['PHP_SELF']."?cat=spgallery&page=main&cid=$cid&page=$prev\\" title='Previous Page'><< Prev</a>";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
$result_final .= " [$i]";
} else {
$result_final .= "\
<a href=\\"".$_SERVER['PHP_SELF']."?cat=spgallery&page=main&cid=$cid&page=$i\\" title='Page ".$i."'>$i</a>";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
$result_final .= "\
<a href=\\"".$_SERVER['PHP_SELF']."?cat=spgallery&page=main&cid=$cid&page=$next\\" title='Next Page'>Next >></a>";
}
$result_final .= "\
</td></tr>";
}
else
{
$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 = "\ <tr><td>No Photo found</td></tr>\
";
}
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 .= "<tr>\
\ <td>
<a href='index.php?cat=spgallery&page=main'>Categories</a> >
<a href='index.php?cat=spgallery&page=main&cid=$cid'>$category_name (Thumbnail Listing)</a></td>\
</tr>\
";
$result_final .= "<tr>\
\ <td align='center'>
<br />
<img src='".$images_dir."/".$photo_filename."' border='0' alt='".$photo_caption."' />
<br />
$photo_caption
</td>
</tr>";
}
}
// Final Output
echo <<<__HTML_END
<h2>Gallery View</h2>
<table width='40%' cellspacing='3' cellpadding='3' border='1' bordercolor='black' align='center'>
$result_final
</table>
__HTML_END;
?>
Thanks in advance for help.