hey there.... i have a page that displays paginated results from an user search ..... the page works fine if the user enters one search term and gets any number of returns..... the page works fine if the user enters two search terms (ex. "new york") and gets less than 10 returns.... the problem starts to arise when the user enters 2+ search terms that result in 10+ returns (this invoking the pagination)... what happens is that anytime a two-term search has 10+ matched, the entire table then gets displayed (ex. user searches for "new york", there are 11 matches for "new york" in the table, but instead of getting one page with 10 results and a 2nd page with one result, he gets the entire table back).... it has something to do with the $userinput variable getting passed strangly in the next and back links... in the URL is shows up as "...&userinput=Array".... i think i need to unset these array values at some point in my script but i cant figure out where to do so.... any help would be greatly appreciated
<?
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['userinput']))
{
$userinput = $_GET['userinput'];
}
else
{
$userinput = explode(" ","{$_POST['criteria']}");
}
if ($userinput == "")
{
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
{
$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]%'";
}
$query .= "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).'&userinput='.$userinput.'">Next</a>';
}
if (($startrow>=10))
{
echo '<a href="search_test.php?startrow='.($startrow-10).'&userinput='.$userinput.'">Back</a>';
}
?>