30) { print "
**Search string must be 3-30 characters**

\n"; $search="INVALID SEARCH"; } # Make sure they're only sending us an alpha-numeric string if( ! preg_match("/^[a-zA-Z0-9# ]+$/", $search)) { print "Special characters such as '\"', '@', '*', '%' are not allowed. "; print "BACK
\n"; print "\n"; exit; } draw_form(); if(isset($do_search)) { if($do_search == 1) { # If they've requested a search and the data all seems valid do it. display_search_results($search); # Draw another search field at the bottom draw_form(); # Jane's pretty footer draw_footer(); } else { # Shouldn't be here, if we are someone is fooling around time to quit! print "Sorry do_search is out of range
"; draw_footer(); exit; } } ############# Functions Below ################# function display_search_results($search) { $cols=3; # How my columns wide $fields=array("images", "description"); # what table fields to populate $go=1; $dbh = mysql_connect('localhost', 'wordpress1', 'clop88exter'); mysql_select_db('wordpress1', $dbh); $terms = explode(" ", $search); if($exact) { $where = "description like '% $search %' or description like '% $search$' or description like '^$search%'"; } else { foreach ($terms as $element) { $where .= "description like '%${element}%' and "; } } $where = preg_replace('/and $/', '', $where); $query = "select images, description, file from items where "; $query .= "$where limit 200"; $sth = mysql_query($query, $dbh); $rows = mysql_num_rows($sth); print "

There where $rows items that matched your search '$search'

\n"; # Build our tables, start fetching categories. if ($rows > 0) { print "\n"; while($go) { for($j=0; $j<$cols; $j++) { $r = mysql_fetch_row($sth); if($r) { # Stop looping if we're out of rows to fetch $ds['images'][$j] = $r[0]; $ds['description'][$j] = "Originally found here.

$r[1]\n"; } else { $go=0; unset($ds['images'][$j]); unset($ds['description'][$j]); unset($ds['file'][$j]); } } foreach($fields as $value) { print "\n"; for($j=0; $j<$cols; $j++) { if($value=='images') { $align='center'; $valign='bottom'; } else { $align='left'; $valign='top'; } print "\n"; } print "\n"; } } # while print "
" . $ds[$value][$j] . "
\n"; print "\n"; } } function draw_form() { echo "
The MGC Search Tool

Exact Phrase
"; } function draw_footer() { ?>
Morning Glory Antiques & Jewelry
at the
A NTIQUEC ONNECTION MALL

and on the internet since 1996
12815 Central NE, Albuquerque, New Mexico, 87123  USA
~ Jane Haley Clarke, owner
Copyright 1996-2005 All rights Reserved