I am trying to get this code working for my advanced search page. I keep getting an error:
Parse error: syntax error, unexpected $end in /home/rach99/public_html/client/search_adv.php on line 298
Which i researched and it said a bracket is missing. but i can't seem to work out from where?
This code was working as a normal search, this is the new code i added:
Code: Select all
if (isset($_GET['search'])) {
$query_sub = "";
//set a flag to use if you need a comma
$comma_flag = 0;
//see if 'name' is not blank
$trimmed = trim($_GET['name']);
if ($trimmed != "") {
$query_sub .= "tassearch.ResName LIKE '%$trimmed%'";
$comma_flag = 1;
}
$trimmed = trim($_GET['cuisine']);
if ($trimmed != "") {
if ($comma_flag == 1) {
$query_sub .= " AND ";
}
$query_sub .= "tascuisine.ResCuisine LIKE '%$trimmed%'";
$comma_flag = 1;
}
$trimmed = trim($_GET['suburb']);
if ($trimmed != "") {
if ($comma_flag == 1) {
$query_sub .= " AND ";
}
$query_sub .= "tassearch.ResSuburb LIKE '%$trimmed%'";
}
$query = "SELECT COUNT(*)
FROM `{$tablename}`
WHERE {$query_sub}`
ORDER BY `{$ordercolumn}`";
Code: Select all
<?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;) --><img src=\"{SMILIES_PATH}/icon_wink.gif\" alt=\";)\" title=\"Wink\" /><!-- s;) -->
$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;
}
if (isset($_GET['search'])) {
$query_sub = "";
//set a flag to use if you need a comma
$comma_flag = 0;
//see if 'name' is not blank
$trimmed = trim($_GET['name']);
if ($trimmed != "") {
$query_sub .= "tassearch.ResName LIKE '%$trimmed%'";
$comma_flag = 1;
}
$trimmed = trim($_GET['cuisine']);
if ($trimmed != "") {
if ($comma_flag == 1) {
$query_sub .= " AND ";
}
$query_sub .= "tascuisine.ResCuisine LIKE '%$trimmed%'";
$comma_flag = 1;
}
$trimmed = trim($_GET['suburb']);
if ($trimmed != "") {
if ($comma_flag == 1) {
$query_sub .= " AND ";
}
$query_sub .= "tassearch.ResSuburb LIKE '%$trimmed%'";
}
$query = "SELECT COUNT(*)
FROM `{$tablename}`
WHERE {$query_sub}`
ORDER BY `{$ordercolumn}`";
// 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>";
?>
Thanks
Rachael