well i figured it out, kinda... it will work when i only search with one variable (ex. if i only type in "montreal" for my search variable), when searching for this one variable, the search performs as it should and paginates as it should.... the problem arises when i search for more than one term (ex. if i search for "new york")... i then get an error as follows:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'and name like '%york%' or address like '%york%' or
so whats happening is that on the second loop (searching for matches to the second variable) something has gone wrong.... i have this exact same script on another page that does not paginate and i can search for multiple terms just fine, so i dont think its the query that is faulty... i think it has something to do with the setting of the $criteria variable after the "if (isset($_GET['criteria']))" line of code, but im really not sure
i really dont know what is going on here... any help would be WONDERFUL... here is my updated code, please let me know if you notice anything that should be changed
<?
include("other.inc");
$connection = mysql_connect($host,$user,$password)or die ("couldn’t connect to server");
$db = mysql_select_db($database,$connection)or die ("Couldn’t select database");
//check if this is the first page
if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow']))
{
//we give the value of the first row to 0
$startrow = 0;
//otherwise we take the value from the URL
}
else
{
$startrow = (int)$_GET['startrow'];
}
//query details table begins
if (isset($_GET['criteria']))
{
$criteria = $_GET['criteria'];
}
else
{
$criteria = $_POST['criteria'];
}
if ($criteria == "")
{
echo "There were no matches found for your search.";
echo "<form name='search' action='show_search.php' method='post'>";
echo "Enter your search criteria:<br>";
echo "<input type='text' name='criteria'><br>";
echo "<input type='submit' name='search' value='Search'>";
echo "</form>";
exit;
}
else
{
$userinput = explode(" ","$criteria");
$query = "SELECT * FROM houses where houseID like '%%'";
$arraycount = count($userinput);
for ($i = 0; $i < $arraycount; $i++)
{
$query .= " and name like '%$userinput[$i]%'
or address like '%$userinput[$i]%'
or city like '%$userinput[$i]%'
or province like '%$userinput[$i]%'
or postalCode like '%$userinput[$i]%'
or phoneNum like '%$userinput[$i]%'
or altPhoneNum like '%$userinput[$i]%'
or description like '%$userinput[$i]%'
or grouping like '%$userinput[$i]%'
or latitude like '%$userinput[$i]%'
or longitude like '%$userinput[$i]%'
LIMIT $startrow, 10";
}
//below is the table layout for results
$result = mysql_query($query) or die (mysql_error($connection));
while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
extract($row);
echo "$name<br>";
}
}
$numrows=mysql_num_rows($result);
//now these are the links
if ($numrows>=10)
{
echo '<a href="search_test.php?startrow='.($startrow+10).'&criteria='.$criteria.'">Next</a>';
}
if (($startrow>=10))
{
echo '<a href="search_test.php?startrow='.($startrow-10).'&criteria='.$criteria.'">Back</a>';
}
?>