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 .= " [$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)."'> </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)."'> </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 (".$total_pages."): ";
// 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 .= " [$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