Hi Everyone,
I currently have a working search based website, a user types in their search into a small search form and searches.
What i would like now is to also have and 'advanced search' on a page where instead of having just the one search box i have it set out like the following:
Name
Cuisine
Location
then the user can type in more than on thing to search for like a restaurant name and a location where it could be?
How would i set up my form so that my search.php will display these results or will i have to have a whole new search.php?
Any help would be awesome.
CODE BELOW
CURRENT FORM WHERE TYPE IN SEARCH:
<form action="search.php" method="get" name="search">
<input name="q" type="text" value=" [code=php]<?php echo $q; ?>[/code] " size="15">
<input name="search" type="submit" value="Search">
</form>
MY SEARCH PAGE: (search.php)
<?php
// Set up some vars to use:
$tablename = 'tassearch'; // Change to the table to search
$searchcolumn = 'ResName'; // Change to the column to search
$searchcolumnb = 'ResSuburb';
$searchcolumna = 'ResCuisine';
$ordercolumn = 'ResName'; // Change to the column to order by
?>
<P>Welcome to example</P>
<?php
// Get the search variable from URL
$var = $_GET['q'] ;
$trimmed = trim($var); //trim whitespace from the stored variable
// If s is sent, then grab it. If it's less than 0, make it 0 ;)
$s = 0;
if(isset($_GET['s']))
{
$s = $_GET['s'];
if($s < 0)
$s = 0;
}
// rows to return
$limit=10;
// check for an empty string and display a message.
if ($trimmed == "")
{
echo "<p>Please enter a search...</p>";
exit;
}
// secure the "trimmed" value
$trimmed = mysql_real_escape_string($trimmed);
// check for a search parameter
if (!isset($var))
{
echo "<p>We dont seem to have a search parameter!</p>";
exit;
}
// Build SQL Query
$query = "SELECT COUNT(*)
FROM `{$tablename}`
WHERE `{$searchcolumn}` LIKE '%$trimmed%' or `{$searchcolumnb}` LIKE '%$trimmed%'
ORDER BY `{$ordercolumn}`"; // EDIT HERE and specify your table and field names for the SQL query
$sql = "SELECT a.tascuisine, t.ResName
FROM tascuisine a
INNER JOIN linktable lt ON a.CusId = lt.FK_CusId
INNER JOIN tablesearch t ON lt.FK_ResNameId = t.ResNameId
WHERE a.CusId = $selectedCusId";
$rslt=mysql_query($query) or die('MySQL Error: ' . mysql_error());
$numrows = mysql_result($rslt, 0, 0);
@mysql_free_result($rslt);
// If we have no results, offer a google search as an alternative
if ($numrows == 0)
{
echo "<h4>Results</h4>";
echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>";
}
// get results
$query = "SELECT *
FROM `{$tablename}`
WHERE `{$searchcolumn}` LIKE '%{$trimmed}%' or `{$searchcolumnb}` LIKE '%{$trimmed}%'
ORDER BY `{$ordercolumn}`
LIMIT {$s}, {$limit}";
$result = mysql_query($query) or die("Couldn't execute query");
// display what the person searched for
echo "<p>You searched for: "" . $var . ""</p>";
// begin to show results set
echo "<p>Results</p>";
$count = 1 + $s ;
while ($row = mysql_fetch_array($result)) {
$link = $row['ResLink'];
$link_title = $row['ResName'];
echo $count . '.) <a href="' . $link . '">' . $link_title . '</a><br />';
$count++;
}
$currPage = (($s/$limit) + 1);
//break before paging
echo "<br />";
// next we need to do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><<
Prev 10</a>  ";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$news=$s+$limit;
echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>";
}
$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
echo "<p>Showing results $b to $a of $numrows</p>";
?>