Hello all,
I'm doing a simple search for a staff system. I want the person searching to get results by entering or part entering first name, surname, or telephone extension and the results to be returned.
So far I have it workign but only on entering or part entering a surname, I cant seem to get the query right for search across all three fields.
my code is:
<?php
// Get the search variable from URL
$var = @$_GET['q'] ;
$trimmed = trim($var); //trim whitespace from the stored variable
// rows to return - set to 99999 for testing
$limit=99999;
// connect to MySQL
mysql_connect("localhost","DBADMIN","DBPASS");
// select database
mysql_select_db("staff") or die("Unable to select database");
// build SQL Query
$query = "SELECT * FROM staffsearch WHERE surname LIKE \"%$trimmed%\"
ORDER BY surname";
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
if ($numrows == 0)
{
// if no results
echo "<p><li class='LSRow'> Sorry, your search:</li><li class='LSRow'> <strong>"" . $trimmed . ""</strong></li><li class='LSRow'> Returned 0 results</li></p>";
}
// determine if s has been passed to script, if not use 0
if (empty($s)) {
$s=0;
}
// get results
$query .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query");
// display results
while ($row= mysql_fetch_array($result)) {
$first_name = $row["first_name"];
$surname = $row["surname"];
$tel = $row["tel"];
echo "<li class='LSRow'><a href='http://intranet/staffsearch/search.lasso?=$surname'>$first_name $surname</a> Ext:$tel</li>" ;
$count++ ;
}
$currPage = (($s/$limit) + 1); ?>
thanks for any help