search results pagination problem !
Posted: Sun Jun 10, 2007 6:17 am
Hi
I have problem with results pagination. When search is applied browser is showing me first 10 results, and links to other pages, but there is a problem with these links (passing variables i think). When i press on one of the links browser is showing me info that search input must be longer then 2 char. (so it clear that search input has not been passed thru the link.)
Here is the code:
go to http://www.webdev.nita-on-line.com/new/movies.php
to see this script in action - (search words that will give you more than 10 results - james, red - for example)
I need some help with this one ....
Thank you in advance.
Nita
I have problem with results pagination. When search is applied browser is showing me first 10 results, and links to other pages, but there is a problem with these links (passing variables i think). When i press on one of the links browser is showing me info that search input must be longer then 2 char. (so it clear that search input has not been passed thru the link.)
Here is the code:
Code: Select all
else if(isset($_POST['submit'])||isset($_POST['search'])||isset($_GET['search'])) // when search button is pressed
{
$PHP_SELF = $_SERVER['HTTP_REFERER'];
$search=$_POST["search"];
$minchar = 2;
if (strlen($search) < $minchar)
{
echo "<span class='info1'>Search must be longer than 2 characters.</span>
}
else
{
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
$max_results = 10;
$from = (($page * $max_results) - $max_results);
$result = mysql_query("SELECT * FROM movies WHERE name LIKE '%$search%'
OR cast LIKE '%$search%' OR director LIKE '%$search%' OR year LIKE '%$search%' OR production LIKE '%$search%' OR genere LIKE '%$search%' OR language LIKE '%$search%' ORDER BY name LIMIT $from, $max_results");
$numrows=mysql_num_rows($result);
if ($numrows == 0)
{
echo "<p>Sorry, your search returned 0 results</p>
}
else
{
while($row=mysql_fetch_array($result))
{
include "display_rec.php";
}
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM movies WHERE name LIKE '%$search%' OR cast LIKE '%$search%' OR director LIKE '%$search%' OR year LIKE '%$search%' OR production LIKE '%$search%' OR genere LIKE '%$search%' OR language LIKE '%$search%' ORDER BY name"),0);
// Figure out the total number of pages.
$total_pages = ceil($total_results / $max_results);
// Build Page Number Hyperlinks
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "
<td class='nav'><a href=\"".$_SERVER['PHP_SELF']."?search=$search&page=$prev\">Previous</a></td>
<td width='2'></td>
";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "<td class='nav'>$i</td>
<td width='2'></td>";
} else {
echo "<td class='nav'><a href=\"".$_SERVER['PHP_SELF']."?search=$search&page=$i\">$i</a></td>
<td width='2'></td>";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<td class='nav'><a href=\"".$_SERVER['PHP_SELF']."?search=$search&page=$next\">Next</a><td>";
}
}
}
}to see this script in action - (search words that will give you more than 10 results - james, red - for example)
I need some help with this one ....
Thank you in advance.
Nita