hey everyone a love all the features u guys ahve added to the gallery and have gotten most of the ones i like working. the only thing i am having problems with right now is the subcategories. i got my database setup like spence_noodle's when he posted his database scheme. i also tried getting his code working with it but for some reason i couldnt. im still pertty new to php and mysql. would anyone that has this working would they be able to post the viewgallery.php script and the uploading/ preuploading script. thanks heres my code right now mabe i am jsut missing something. only got the view gallery script so far having started the other ones
Code:
<?php
include("gallery/config.php");
// initialization
$result_array = array();
$counter = 0;
$cid = (int)($_GET['cid']);
$pid = (int)($_GET['pid']);
// Category Listing
$number_of_categories_in_row = 1;
if( empty($cid) && empty($pid) )
{
$cat = mysql_query( "SELECT c.category_id, c.category_name, c.category_parent, c.category_des, COUNT(p.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 ORDER BY c.category_des ASC" );
while( $row = mysql_fetch_array( $cat ) )
{
if($row[2] == 0)
{
$cat_array[] = "<font face='Verdana, Arial, Helvetica, sans-serif' size='1'><a href='cat_user.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[4].")</font><br />";
}
if($row[2] > 0)
{
$subresult = mysql_query("SELECT category_id,category_name,category_parent,category_des FROM gallery_category WHERE category_name='".$row[1]."' ORDER BY category_des ASC");
while( $sub_result = mysql_fetch_array( $subresult ) )
{
if ($sub_result[2] !='')
{
$line1 = explode('/', $sub_result[3]);
$line2 = implode(', ', $line1);
$words1 = preg_replace('/\s+/', '', $line2);
$words2 = str_replace(',', ' ', $words1);
$level = substr_count($words2," ");
if($level == 1)
{
$add = str_repeat(' ', 0);
}
if($level == 2)
{
$add = str_repeat(' ', 2);
}
if($level == 3)
{
$add = str_repeat(' ', 4);
}
$subcat = mysql_query( "SELECT COUNT(p.photo_id)
FROM gallery_category as c
LEFT JOIN gallery_photos as p ON p.photo_category = '".$sub_result[0]."'
GROUP BY c.category_id ORDER BY c.category_name ASC" );
$sub_cat = mysql_fetch_array( $subcat );
$cat_array[] = "<font face='Verdana, Arial, Helvetica, sans-serif' size='1'>".$add."|-<a href='cat_user.php?cid=".$row[0]."'>".$sub_result[1]."</a> "."(".$sub_cat[0].")</font><br />";
}
}
}
}
mysql_free_result( $cat );
mysql_free_result( $subresult );
foreach($cat_array as $category_link)
{
if($counter == $number_of_categories_in_row)
{
$counter = 1;
}
else
$counter++;
$cat_final .= "$category_link";
}
}
//Final result
echo "$cat_final";
// 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 = 12;
// 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 = "\t<tr><td>No Category found</td></tr>\n";
}
else
{
while( $row = mysql_fetch_array( $result ) )
{
$result_array[] = "<a href='gallery.php?cid=$cid&pid=".$row[0]."'><img src='".$images_dir."/tb_".$row[2]."' border='0' alt='".$row[1]."' /><br />".$row[1]."</a>";
}
mysql_free_result( $result );
$result_final = "<tr>\n";
foreach($result_array as $thumbnail_link)
{
if($counter == $number_of_thumbs_in_row)
{
$counter = 1;
$result_final .= "\n</tr>\n<tr>\n";
}
else
$counter++;
$result_final .= "\t<td>".$thumbnail_link."</td>\n";
}
if($counter)
{
if($number_of_photos_in_row-$counter)
$result_final .= "\t<td colspan='".($number_of_thumbs_in_row-$counter)."'> </td>\n";
$result_final .= "</tr>\n";
// 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."' class='tcat'>\nPages (".$total_pages."): ";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SELF']."?cid=$cid&page=$prev\" title='Previous Page'><<</a>";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
$result_final .= " [$i]";
} else {
$result_final .= "\n<a href=\"".$_SERVER['PHP_SELF']."?cid=$cid&page=$i\" title='Page ".$i."'>$i</a>";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SELF']."?cid=$cid&page=$next\" title='Next Page'>>></a>";
}
$result_final .= "\n</td></tr>";
}
else
{
$result_final .= "\n";
}
}
}
}
// 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 );
//fill pid_array with sorted pids in current category
$result = mysql_query( "SELECT photo_id FROM gallery_photos WHERE photo_category='".addslashes($cid)."' ORDER BY photo_id" );
$ct = mysql_num_rows( $result );
while ($row = mysql_fetch_array($result)) {
$pid_array[] = $row[0];
}
mysql_free_result( $result );
if( empty( $nr ) )
{
$result_final = "\t<tr><td>No Photo found</td></tr>\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 .= "<tr>\n\t<td>
<a href=gallery.php>Albums</a> >
<a href=gallery.php?cid=$cid'>$category_name</a><br><br></td>\n</tr>\n";
// display previous and next links if more than one photo
if ($ct > 1) {
$key = array_search($pid, $pid_array);
$prev = $key - 1;
if ($prev < 0) $prev = $ct - 1;
$next = $key + 1;
if ($next == $ct) $next = 0;
$result_final .= "<tr><td colspan='10'><center>";
$result_final .= "<a href=gallery.php?cid=$cid&pid=".$pid_array[$prev]."'>Previous</a> ";
$result_final .= "(".($key+1)." / ".$ct.") ";
$result_final .= "<a href=gallery.php?cid=$cid&pid=".$pid_array[$next]."'>Next</a>";
$result_final .= "</center></td></tr>";
}
$result_final .= "<tr>\n\t<td align='center'>
<img src='".$images_dir."/".$photo_filename."' border='0' alt='".$photo_caption."' width='500' />
<br />
$photo_caption
</td>
</tr>";
}
}
// Final Output
echo <<<__HTML_END
<html>
<head>
<title>Gallery View</title>
</head>
<body>
<table width='80%' border='0' align='center' style='width: 80%;'>
$result_final
</table>
</body>
</html>
__HTML_END;
?>
with the code like this i get this error "
Parse error: syntax error, unexpected T_ELSE in /var/www/gallery.php on line 103"
the block around line 103 is
Code:
foreach($cat_array as $category_link)
{
if($counter == $number_of_categories_in_row)
{
$counter = 1;
}
else
$counter++;
$cat_final .= "$category_link";
}
}
i think there is probly even more errors here but im not sure
im not sure what i am doing worng here but any help with this would be great. thanks in advance
Bookmarks