Build An Automated PHP Gallery System In Minutes

sorry to hear you are having problems.

at the moment the only thing i can think what could be causing this is that you have not called the table ‘gallery_category’, then placed the above fields.

also a table called ‘gallery_photos’ with the fields ‘photo_id’ and ‘photo_category’.

i’ll have a more detailed look at it, plus i may have made a newer version.

will post results, but try them first.

spence

ok Vibex, i’ve got the subcategory to work. you will need to change category_des to catgeory_desc.

i think it may have been this:

COUNT(photo_id) and p.photo_category = c.category_id that was causing the problems

i’ve changed the above to this:

COUNT(p.photo_id) and p.photo_category=c.category_id

the code below does work, i’ve tested it on my website.


 <?php
 include("config.inc.php");
 
 // initialization
 $cat_array = array();
 $counter = 0;
 
 // 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('&nbsp;', 0);
 					}
 					
 					if($level == 2)
 					{
 		    		$add = str_repeat('&nbsp;', 2);
 					}
 					
 					if($level == 3)
 					{
 		    		$add = str_repeat('&nbsp;', 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";
 ?>
 

let us know if thats sorted it out.

spence

Spence,

No Dice. same errors, different lines numbers:
http://robandlisa.ca/gallery/subcategory2.php

I’m missing something, here, that I am blinded to.
here’s the version I am working on, slightly different structuring; but, the same errors.

Thanks for all the help.

whats your tables look like in mysql?

are they like this:

gallery_category:
[color=#dd0000]
[color=black]


  -- 
  -- Table structure for table `gallery_category`
  -- 
  
  CREATE TABLE `gallery_category` (
    `category_id` bigint(20) unsigned NOT NULL auto_increment,
    `category_name` varchar(250) NOT NULL default '',
    `category_parent` bigint(250) NOT NULL default '0',
    `category_desc` varchar(250) NOT NULL default '',
    PRIMARY KEY  (`category_id`),
    KEY `category_id` (`category_name`)
  ) TYPE=MyISAM AUTO_INCREMENT=180 ;
  

gallery_photos:


  -- 
  -- Table structure for table `gallery_photos`
  -- 
  
  CREATE TABLE `gallery_photos` (
    `photo_id` bigint(20) unsigned NOT NULL auto_increment,
    `photo_category` bigint(20) default NULL,
    PRIMARY KEY  (`photo_id`),
    KEY `photo_id` (`photo_category`)
  ) TYPE=MyISAM AUTO_INCREMENT=343 ;
  

with gallery_photos there will be more fields, above is just for the script above.

spence
[/color][/color]

gallery_category

CREATE TABLE gallery_category (
category_id bigint(20) unsigned NOT NULL auto_increment,
category_name varchar(50) NOT NULL default ‘0’,
category_parent int(11) NOT NULL default ‘0’,
category_desc varchar(60) NOT NULL default ‘’,
PRIMARY KEY (category_id),
KEY category_id (category_id)
) TYPE=MyISAM AUTO_INCREMENT=12 ;

gallery_photos

CREATE TABLE gallery_photos (
photo_id bigint(20) unsigned NOT NULL auto_increment,
photo_filename varchar(25) default NULL,
photo_caption text,
photo_category bigint(20) unsigned NOT NULL default ‘0’,
photo_dateadded datetime NOT NULL default ‘0000-00-00 00:00:00’,
photo_order tinyint(20) unsigned NOT NULL default ‘13’,
PRIMARY KEY (photo_id),
KEY photo_id (photo_id)
) TYPE=MyISAM AUTO_INCREMENT=202 ;

is there any categories within the gallery_category table?

your mysql tables look fine, just want to know if theres any data been inputed into the gallery_category table.

spence

I found the error, but don’t know the solutions.

data entered into the database included an apostrophe ’ in the category name.

this caused the errors.

did you enter the data through phpmyadmin?

I used the admin.php interface to add the category and remove the 's from the category.

weldone Bill007, looking very good.

nice to see you’ve got it working.

spence

I thought this might be handy an improved Catergory Gallery view
Example Below
viewgallery.phpviewgallery.php
a main catergory gallery with category and image link

Any way this has been a great journey and i have built a fine gallery site for Artist Friend THANKS TO THIS FINE THREAD and all the people who have developed it Its been great to see how some have taken beyond

Cool Guys

Oh and Hi Spence Doodle

include("tools/config.inc.php");
    include("design.inc.php");
	//include("latest_photos_added.php");
	// initialization
	$design_header;
	$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 = 1;

		$result = mysql_query( "SELECT c.category_id, c.category_name, photo_filename, 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[] = "<b><a href='viewgallery.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[3].")</b><br /><hr />
			<a href='viewgallery.php?cid=".$row[0]."'><img src='".$images_dir."/tb_".$row[2]."'></a>"; 

		
		}
								
		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 .= "\	<td colspan='".($number_of_categories_in_row-$counter)."'>&nbsp;</td>\
";

			   
                $result_final.= "</tr>";
               
		}
	}

	// Thumbnail Listing

	else if( $cid && empty( $pid ) )
	{
		$number_of_thumbs_in_row = 2;
    // 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_description,photo_price,photo_filename FROM gallery_photos WHERE photo_category='".addslashes($cid)."'LIMIT $from, $max_results" );
		$nr = mysql_num_rows( $result );
		if( empty( $nr ) )
		{
			//$design_header
			$result_final = "\	<tr><td><h1>No Category found</h1></td></tr>\
";
		    //$design_footer
		}
		else
		{
			while( $row = mysql_fetch_array( $result ) )
			{
				
				
				$result_array[] = "<a href='viewgallery.php?cid=$cid&pid=".$row[0]."'>
				                   <img src='".$images_dir."/tb_".$row[4]."' border='2' alt='".$row[1]."'</a> <br />
								   <a href='viewgallery.php?cid=$cid&pid=".$row[0]."'>".$row[3]."<br />".$row[1]."</a>";
			
			
			// $result_array[] ="<a href='viewgallery.php?cid=".$row[0]."'>".$row[1]."</a> ";
			
			}
			mysql_free_result( $result );	
            //$design_header
			$result_final = "<tr>\
";
	        //$design_footer
			foreach($result_array as $thumbnail_link)
			{
				if($counter == $number_of_thumbs_in_row)
				{	
					$counter = 1;
					$result_final .= "\
</tr>\
<tr>\
";
				}
				else
				$counter++;
               // $design_header
				$result_final .= "\	<td>".$thumbnail_link."</td>\
";
			   // $design_footer
			}
	
			if($counter)
			{
				if($number_of_photos_in_row-$counter)
			$result_final .= "\	<td colspan='".($number_of_photos_in_row-$counter)."'>&nbsp;</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."' class='tcat'>\
Pages&nbsp;(".$total_pages."):&nbsp;"; 


// Build Previous Link 
if($page > 1){ 
    $prev = ($page - 1); 
    $result_final .=  "\
<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 .= "&nbsp;[$i]"; 
        } else { 
            $result_final .=  "\
<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 .=  "\
<a href=\\"".$_SERVER['PHP_SELF']."?cid=$cid&page=$next\\" title='Next Page'>>></a>"; 
} 
$result_final .=  "\
</td></tr>"; 

}
else
{
$result_final .=  "\
";
}			
}
}
}
	// Full Size View of Photo
	else if( $pid )
	{
		$result = mysql_query( "SELECT photo_description,photo_price,photo_caption,photo_filename,photo_category FROM gallery_photos WHERE photo_id='".addslashes($pid)."'" );
		list($photo_description,$photo_price,$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 align='center'>
						      <h3><a href='viewgallery.php'>Return to Art Series List</a> > 
						      <a href='viewgallery.php?cid=$cid'>You are viewing the Art Series of $category_name</a></h3></td>\
  </tr>\
";
			$result_final .= "<tr>\
\	<td align='center'>
					          <h1>$photo_caption</h1>
					          <br />
					          <h2>$photo_price</h2><br />$photo_description<br />
							  <a href='http://www.art-light.co.nz/security_image/contact.php'>To Purchase this Art piece Contact me</a></p>
					          <br />
					          <img src='".$images_dir."/".$photo_filename."' border='0' alt='".$photo_caption."' />
					          <br />
					          </td>
					</tr>";
}		
}	
$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 );
// Final Output
echo <<<__HTML_END

$design_header
<h1 align='center'>  Art Light Gallery Rooms<br /><br />
<table width='100%' border='0' align='centre' style='width: 50%;';>
$result_final		
</table><br /><br /><br /><br />
$design_footer
__HTML_END;

Also at the bottom of this script is some code

eg below

$design_header
<h1 align=‘center’> Art Light Gallery Rooms<br /><br />
<table width=‘100%’ border=‘0’ align=‘centre’ style=‘width: 50%;’;>
$result_final
</table><br /><br /><br /><br />
$design_footer

This is how you bring in your own design put your template site design in between the appropriate Variable $design_header=<<<__HTML_END or $design_footer=<<<__HTML_END no white space after <<<__HTML_END or it wont work

<?php
$design_header=<<<__HTML_END
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="content-type"content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="#" />
</head>
<body>
<div id="header">
</div> 
<div id="content">
__HTML_END;


$design_footer=<<<__HTML_END
<div id="footer">
</div>
</div>
__HTML_END;
?>

If anyone wants more I can give you more have some great back end features and other script for this project

Over and out Bill007 the Kiwi down under

Kia ora VibeX and Spence doodle

Hi its Bill007 I think youll find VibeX that you need to adjust your $row [ ?] variables thru out your script do it by trial and error or go to your http://localhost/phpmyadmin/ AND INVESTIGATE THE ROW NUMBERS sounds like its set up for spence doodles Database table which is why it works for him first time
I had the same problem but then realized that the database rows where culprit behind those MYSQL WARNINGS you need to find out your exact table rows number in the Database

$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");

Good luck Ill keep tuned in BILL007

hi Bill007, thankx for the scipt above and it’s nice to see someone who likes our script snippets to help others along.

as for the above answer, yes, oh my god! thats it, got to be. his table must be (will be different) and will be getting the info in a different order, etc…

again thanx for pointing that out, i’ve been busy learning CISCO (ccna) and job hunting.

spence

Hey sorry for the spence doodle phrase I feel terrible

Well Ive been outa the loop with me Holiday

Poor excuse (holiday Glow has since passed)

You thinking of an Networking job

Good luck My sister is in london at the moment working for some IT company getting paid truck loads So some one of your Talent should be scooped up immediately

well, you would think so. i’ve had my CV on Monster.co.uk for nearly two weeks and nothing as yet.

don’t worry about the doodle thing, i’ve been called much worse, just the other day for example, but I won’t go into that, too rude. lol

london seems to place for IT at the mo, but i’m trying for a much nearer job up north(west) area. I will wait and see.

cheers,

spence

I want to able to search Categories As-well can you do it with a MYSQL LEFT JOIN

By the Way what a great Search Script and I love the way it displays

Nice One

<?php
          include "tools/config.inc.php";
          include "design.inc.php";
          $query_array = array();
          $counter = 0;
  
          // get the word from the html address
          if (!isset($_GET['searchword'])){
              // recieve the word to search from search form
              $word = $_POST['word'];
              $dbword = $word;
              // insert the word into the database
            mysql_query( "INSERT INTO gallery_search (search_date, search_word) VALUES(NOW(), '".$word."') ");
          } else {
            // if no word from the form has been sent $_GET the word instead from the html address
              $searchw = $_GET['searchword'];
              // select the word from the database
            $search = mysql_query( "SELECT search_word, search_date FROM gallery_search WHERE search_word='".$searchw."' ");
              $searchwr = mysql_fetch_array( $search );
              $dbword = $searchwr[0];
          }
          
          $number_of_thumbs_in_row = 2;
  
          // 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);
  
                // query the database for this word in boolean mode
             $query = @mysql_query( "SELECT photo_id, photo_filename, photo_caption, photo_description,photo_price, photo_category,photo_date FROM gallery_photos WHERE photo_caption LIKE '%".$dbword."%' OR photo_description LIKE '%".$dbword."%' OR photo_price LIKE '%".$dbword."%'OR photo_category LIKE '%".$dbword."%' ORDER BY photo_date DESC LIMIT $from, $max_results");
  
                $nr = @mysql_num_rows( $query );
                  
                  // check $nr for results
                  if( empty( $nr ) )
                  {
                     // if no reults display message below
                     $query_final = "<tr><td><div align=\\"center\\"><font face='Verdana, Arial, Helvetica, sans-serif' bgcolor='#C9F9F9' size='4'><span class='style5'><h1>No Art Works found! Please try another word or phrase</h1><a href='../index.php'>Back to Administration Page</a><br /></span></font></div></td></tr>";
                  }
                  else
                  {
                     while( $row = mysql_fetch_array( $query ) )
                     {                          
                      // if word found get each photo and add padding on the left and right
                      $image_size = getimagesize( $images_dir.'/tb_'.$row[1] );
                      
                      if($image_size[0] < 100)
                      {
                           $width_size = (int)(120 - $image_size[0]);
                           $pad_r = (int)($width_size / 2);
                           $pad_l = $pad_r;
                      }
                      else
                      {
                           $pad_r = 10;
                           $pad_l = 10;
                      }
                      
                      // list thumbnail(s) with details, etc..
                      $catquery = @mysql_query( "SELECT category_name, category_id FROM gallery_category WHERE category_id='".addslashes($row[5])."'" );
                          list($category_name, $category_id) = mysql_fetch_array( $catquery );
                          mysql_free_result( $catquery );
                          
                          $query_array[] = "<tr>
                              <td>
                               <table align='center' width='50%' border='0' cellspacing='1' cellpadding='1'>
        <tr>
        <td width='20%'  rowspan='10' class='photo_boarder' bgcolor='#C9F9F9'><div align='center'><a href='".$images_dir."/".$row[1]."'><img src='".$images_dir."/tb_".$row[1]."' border='0' alt='".$row[3]."' style='padding-top: 5px; padding-right: ".$pad_r."px; padding-left: ".$pad_l."px; padding-bottom: 5px;' /></a></div>
          </td>

     <td width='300' valign='top' bgcolor='#C9F9F9'><span class='style5'><b>Art Title :</b></span> $row[2] </td>
        </tr>
        <tr>
        <td valign='top'><span class='style5'><b>Art Category :</b></span> $category_name </td>
        </tr>
        <tr>
        <td valign='top' bgcolor='#C9F9F9'><span class='style5'><font color='#FF0000'> <a href='http://art-light.co.nz/contact.php'><b>Buy Now:</b></a></font></span> $row[4] </td>
        </tr>
        <tr>
        <td valign='top'><span class='style5'><b>Date Added :</b></span> $row[6]</td>
        </tr>
        <tr>
          <td valign='top' bgcolor='#C9F9F9'><span class='style5'><b>Photo ID:</b></span> $row[0] </td>
        </tr>
  </table>
      </td>
          </tr>";
                          }
                     mysql_free_result( $query );
                        
                     // reults - display message below
                     $query_final = "$design_header<tr><td><div align='center'><font face='Verdana, Arial, Helvetica, sans-serif' size='4' class='style5'><h1>Art Light Search results</h1><br /></font></div></td></tr><br />";
                        
                     // loop through until no more adverts can be found with that word
                  foreach($query_array as $thumbnail_link)
                          {
                             if($counter == $number_of_thumbs_in_row)
                             {        
                                     $counter = 1;
                             }
                             else
                             $counter++;
                          
                          $query_final .= "<td><div align=\\"center\\">".$thumbnail_link."</div></td>";
                          }
                        
                     // figure out the total number of results in DB:
                          $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM gallery_photos WHERE photo_caption LIKE '%".$dbword."%' OR photo_description LIKE '%".$dbword."%' OR photo_price LIKE '%".$dbword."%' "),0);
                          
                     // here check how many thumbs are displayed.
                     // if more than $max_results is set to build page number, prev, next links
                     if ($total_results == 8)
                     { // build links for one page only
  
                      // build Page Number Hyperlinks
                          $query_final .= "<tr><td colspan='".$number_of_thumbs_in_row."'><span class='style5'><b>Showing Page: 1 of 1</b></span><br><br>";
                        } else {
                      // build more than one page if counter is more than 8        
                      // figure out the total number of pages. Always round up using ceil()
                      $total_pages = ceil($total_results / $max_results);
                          
                      // build Page Number Hyperlinks
                          $query_final .= "<tr><td colspan='".$number_of_thumbs_in_row."'><span class='style5'><b>Showing Page: ".$page.' of '.$total_pages."</b></span><br/>";
                      
                      // build Previous Link
                          if($page > 1){
                              $prev = ($page - 1);
                              $query_final .= " <a href=\\"".$_SERVER['PHP_SELF']."?searchword=".$word.$searchwr[0]."&page=$prev\\" title='Previous Page' class='style5'><< Prev</a>";
                      }
  
                          // build the number of pages
                          for($i = 1; $i <= $total_pages; $i++){
                              if(($page) == $i){
                               $query_final .= "&nbsp;[$i]";
                          } else {
                               $query_final .= " <a href=\\"".$_SERVER['PHP_SELF']."?searchword=".$word.$searchwr[0]."&page=$i\\" title='Page ".$i."' class='style5'>$i</a>";
                          }
                      }
  
                          // build Next Link
                          if($page < $total_pages){
                              $next = ($page + 1);
                          $query_final .= " <a href=\\"".$_SERVER['PHP_SELF']."?searchword=".$word.$searchwr[0]."&page=$next\\" title='Next Page' class='style5'>Next >></a>";
                          $query_final .= "</td></tr><br /><br />";
                      }
                      else
                      {
                          $query_final .= "<p>";
                      }
      }
  }
  echo "$query_final<br/><br/>";
  ?> 

Regards Bill0077

cheers Bill007 :wink:

yes you could do a LEFT JOIN with the same word.

you could do it this way as well:


 $query = @mysql_query( "SELECT photo_id, photo_filename, photo_caption, photo_description, photo_price, photo_category, photo_date, category_name FROM gallery_photos as a, gallery_category as b WHERE a.photo_caption LIKE '%".$dbword."%' OR a.photo_description LIKE '%".$dbword."%' OR a.photo_price LIKE '%".$dbword."%'OR a.photo_category LIKE '%".$dbword."%' OR b.category_name ORDER BY a.photo_date DESC LIMIT $from, $max_results");
 

spence

Still no Category search Hmmmmm

And I get triple images out put

Will do some mucking around with it and see if this thing can work

I think that search script would be perfect if it could search and retreive Categorys

Thanks for some direction Though

Got any clues as to why the triplicate output

Bill007 (:

Spence modified the Search.php output a little
I made links out of the category names and linked the category name and image to a more descriptive and larger image

Search.php output now flows to the same lines as the viewgallery.php script an example of the search .php in action below
http://art-light.co.nz/gallery/search.php

an example of the veiwgallery.phpin action below click on the image
How the veiwgallery.php script looks as an idea of getting the same look and feel as search php

search.php Below ties in with viewgallery.php


<?php
          include "tools/config.inc.php";
          include "design.inc.php";
          $query_array = array();
          $counter = 0;
  
          // get the word from the html address
          if (!isset($_GET['searchword'])){
              // recieve the word to search from search form
              $word = $_POST['word'];
              $dbword = $word;
              // insert the word into the database
            mysql_query( "INSERT INTO gallery_search (search_date, search_word) VALUES(NOW(), '".$word."') ");
          } else {
            // if no word from the form has been sent $_GET the word instead from the html address
              $searchw = $_GET['searchword'];
              // select the word from the database
            $search = mysql_query( "SELECT search_word, search_date FROM gallery_search WHERE search_word='".$searchw."' ");
              $searchwr = mysql_fetch_array( $search );
              $dbword = $searchwr[0];
          }
          
          $number_of_thumbs_in_row = 2;
  
          // 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);
  
                // query the database for this word in boolean mode
             $query = @mysql_query( "SELECT photo_id, photo_filename, photo_caption, photo_description,photo_price, photo_category,photo_date FROM gallery_photos WHERE photo_caption LIKE '%".$dbword."%' OR photo_description LIKE '%".$dbword."%' OR photo_price LIKE '%".$dbword."%'OR photo_category LIKE '%".$dbword."%' ORDER BY photo_date DESC LIMIT $from, $max_results");
			  //$query = @mysql_query( "SELECT photo_id, photo_filename, photo_caption, photo_description, photo_price, photo_category, photo_date, category_name FROM gallery_photos as a, gallery_category as b WHERE a.photo_caption LIKE '%".$dbword."%' OR a.photo_description LIKE '%".$dbword."%' OR a.photo_price LIKE '%".$dbword."%'OR a.photo_category LIKE '%".$dbword."%' OR b.category_name ORDER BY a.photo_date DESC LIMIT $from, $max_results"); 
  
                $nr = @mysql_num_rows( $query );
                  
                  // check $nr for results
                  if( empty( $nr ) )
                  {
                     // if no reults display message below
                     $query_final = "<tr><td><div align=\\"center\\"><font face='Verdana, Arial, Helvetica, sans-serif' bgcolor='#C9F9F9' size='4'><span class='style5'><h1>No Art Works found! Please try another word or phrase</h1><a href='../index.php'>Back to Administration Page</a><br /></span></font></div></td></tr>";
                  }
                  else
                  {
                     while( $row = mysql_fetch_array( $query ) )
                     {                          
                      // if word found get each photo and add padding on the left and right
                      $image_size = getimagesize( $images_dir.'/tb_'.$row[1] );
                      
                      if($image_size[0] < 100)
                      {
                           $width_size = (int)(120 - $image_size[0]);
                           $pad_r = (int)($width_size / 2);
                           $pad_l = $pad_r;
                      }
                      else
                      {
                           $pad_r = 20;
                           $pad_l = 20;
                      }
                      
                      // list thumbnail(s) with details, etc..
                      $catquery = @mysql_query( "SELECT category_name, category_id FROM gallery_category WHERE category_id='".addslashes($row[5])."'" );
                          list($category_name, $category_id) = mysql_fetch_array( $catquery );
                          mysql_free_result( $catquery );
                          
                          $query_array[] = "<tr>
                              <td>
                               <table align='center' width='80%' border='0' cellspacing='1' cellpadding='1'>
        <tr>
        <td width='30%'  rowspan='10' class='photo_boarder' bgcolor='#C9F9F9'><div align='center'><a href='viewgallery.php?cid=$cid&pid=".$row[0]."'><img src='".$images_dir."/tb_".$row[1]."' border='0' alt='".$row[3]."' style='padding-top: 5px; padding-right: ".$pad_r."px; padding-left: ".$pad_l."px; padding-bottom: 5px;' /></a></div>
          </td>
     <td width='300' valign='top' bgcolor='#C9F9F9'><span class='style5'><b>Art Title :</b></span> <a href='viewgallery.php?cid=$cid&pid=".$row[0]."'>$row[2] </a></td>
        <tr>
        <td valign='top'><span class='style5'><b>Art Category :</b></span> $category_name </td>
        </tr>
        <tr>
        <td valign='top' bgcolor='#C9F9F9'><span class='style5'><font color='#FF0000'> <a href='http://art-light.co.nz/contact.php'><b>Buy Now:</b></a></font></span> $row[4] </td>
        </tr>
        <tr>
        <td valign='top'><span class='style5'><b>Date Added :</b></span> $row[6]</td>
        </tr>
        <tr>
          <td valign='top' bgcolor='#C9F9F9'><span class='style5'><b>Photo ID:</b></span> $row[0] </td>
        </tr>
  </table>
      </td>
          </tr>";
                          }
                     mysql_free_result( $query );
                        
                     // reults - display message below
                     $query_final = "$design_header<tr><td><div align='center'><font face='Verdana, Arial, Helvetica, sans-serif' size='4' class='style5'><h1>Art Light Search results</h1><br /></font></div></td></tr><br />";
                        
                     // loop through until no more adverts can be found with that word
                  foreach($query_array as $thumbnail_link)
                          {
                             if($counter == $number_of_thumbs_in_row)
                             {        
                                     $counter = 1;
                             }
                             else
                             $counter++;
                          
                          $query_final .= "<td><div >".$thumbnail_link."</div></td>";
                          }
                        
                     // figure out the total number of results in DB:
                          $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM gallery_photos WHERE photo_caption LIKE '%".$dbword."%' OR photo_description LIKE '%".$dbword."%' OR photo_price LIKE '%".$dbword."%' "),0);
                          
                     // here check how many thumbs are displayed.
                     // if more than $max_results is set to build page number, prev, next links
                     if ($total_results == 8)
                     { // build links for one page only
  
                      // build Page Number Hyperlinks
                          $query_final .= "<tr><td colspan='".$number_of_thumbs_in_row."'><span class='style5'><b>Showing Page: 1 of 1</b></span><br><br>";
                        } else {
                      // build more than one page if counter is more than 8        
                      // figure out the total number of pages. Always round up using ceil()
                      $total_pages = ceil($total_results / $max_results);
                          
                      // build Page Number Hyperlinks
                          $query_final .= "<tr><td colspan='".$number_of_thumbs_in_row."'><span class='style5'><b>Showing Page: ".$page.' of '.$total_pages."</b></span><br/>";
                      
                      // build Previous Link
                          if($page > 1){
                              $prev = ($page - 1);
                              $query_final .= " <a href=\\"".$_SERVER['PHP_SELF']."?searchword=".$word.$searchwr[0]."&page=$prev\\" title='Previous Page' class='style5'><< Prev</a>";
                      }
  
                          // build the number of pages
                          for($i = 1; $i <= $total_pages; $i++){
                              if(($page) == $i){
                               $query_final .= "&nbsp;[$i]";
                          } else {
                               $query_final .= " <a href=\\"".$_SERVER['PHP_SELF']."?searchword=".$word.$searchwr[0]."&page=$i\\" title='Page ".$i."' class='style5'>$i</a>";
                          }
                      }
  
                          // build Next Link
                          if($page < $total_pages){
                              $next = ($page + 1);
                          $query_final .= " <a href=\\"".$_SERVER['PHP_SELF']."?searchword=".$word.$searchwr[0]."&page=$next\\" title='Next Page' class='style5'>Next >></a>";
                          $query_final .= "</td></tr><br /><br />";
                      }
                      else
                      {
                          $query_final .= "<p>";
                      }
      }
  }
  echo "$query_final<br/><br/>";
  ?> 

viewgallery.php

<?php
	include("tools/config.inc.php");
    include("design.inc.php");
	//include("latest_photos_added.php");
	// initialization
	$design_header;
	$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 = 1;

		$result = mysql_query( "SELECT c.category_id, c.category_name, photo_filename, 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[] = "<hr /><b><a href='viewgallery.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[3].")</b><br />
			<a href='viewgallery.php?cid=".$row[0]."'><img src='".$images_dir."/tb_".$row[2]."'></a>"; 

		
		}
								
		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 .= "\	<td colspan='".($number_of_categories_in_row-$counter)."'>&nbsp;</td>\
";

			   
                $result_final.= "</tr>";
               
		}
	}

	// Thumbnail Listing

	else if( $cid && empty( $pid ) )
	{
		$number_of_thumbs_in_row = 2;
    // 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_description,photo_price,photo_filename FROM gallery_photos WHERE photo_category='".addslashes($cid)."'LIMIT $from, $max_results" );
		$nr = mysql_num_rows( $result );
		if( empty( $nr ) )
		{
			//$design_header
			$result_final = "\	<tr><td><h1>No Category found</h1></td></tr>\
";
		    //$design_footer
		}
		else
		{
			while( $row = mysql_fetch_array( $result ) )
			{
				
				
				$result_array[] = "<a href='viewgallery.php?cid=$cid&pid=".$row[0]."'>
				                   <img src='".$images_dir."/tb_".$row[4]."' border='2' alt='".$row[1]."'</a> <br />
								   <a href='viewgallery.php?cid=$cid&pid=".$row[0]."'>".$row[3]."<br />".$row[1]."</a>";
			
			
			// $result_array[] ="<a href='viewgallery.php?cid=".$row[0]."'>".$row[1]."</a> ";
			
			}
			mysql_free_result( $result );	
            //$design_header
			$result_final = "<tr>\
";
	        //$design_footer
			foreach($result_array as $thumbnail_link)
			{
				if($counter == $number_of_thumbs_in_row)
				{	
					$counter = 1;
					$result_final .= "\
</tr>\
<tr>\
";
				}
				else
				$counter++;
               // $design_header
				$result_final .= "\	<td>".$thumbnail_link."</td>\
";
			   // $design_footer
			}
	
			if($counter)
			{
				if($number_of_photos_in_row-$counter)
			$result_final .= "\	<td colspan='".($number_of_photos_in_row-$counter)."'>&nbsp;</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."' class='tcat'>\
Pages&nbsp;(".$total_pages."):&nbsp;"; 


// Build Previous Link 
if($page > 1){ 
    $prev = ($page - 1); 
    $result_final .=  "\
<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 .= "&nbsp;[$i]"; 
        } else { 
            $result_final .=  "\
<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 .=  "\
<a href=\\"".$_SERVER['PHP_SELF']."?cid=$cid&page=$next\\" title='Next Page'>>></a>"; 
} 
$result_final .=  "\
</td></tr>"; 

}
else
{
$result_final .=  "\
";
}			
}
}
}
	// Full Size View of Photo
	else if( $pid )
	{
		$result = mysql_query( "SELECT photo_description,photo_price,photo_caption,photo_filename,photo_category FROM gallery_photos WHERE photo_id='".addslashes($pid)."'" );
		list($photo_description,$photo_price,$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 align='center'>
						      <h3><a href='viewgallery.php'>Return to Art Series List</a> > 
						      <a href='viewgallery.php?cid=$cid'>You are viewing the Art Series of $category_name</a></h3></td>\
  </tr>\
";
			$result_final .= "<tr>\
\	<td align='center'>
					          <h1>$photo_caption</h1>
					          <br />
					          <h2>$photo_price</h2><br />$photo_description<br />
							  <a href='http://www.art-light.co.nz/security_image/contact.php'>To Purchase this Art piece Contact me</a></p>
					          <br />
					          <img src='".$images_dir."/".$photo_filename."' border='0' alt='".$photo_caption."' />
					          <br />
					          </td>
					</tr>";
}		
}	
$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 );
// Final Output
echo <<<__HTML_END

$design_header
<h1 align='center'>  Art Lights Main  $category_name Gallery Room $cid<br /><br />
<table width='100%' border='0' align='center' style='width:60%;';>
$result_final		
</table><br /><br /><br /><br />
$design_footer
__HTML_END;
?>

Regards Bill