php pagination error

i recently added a pagination script to my search script which uses a dropdown menu for user inputs for the search. the pagination displays the first page alright but the following pages are all blank, I think it has to do with linking the pagination to the dropdown search but I dont know how to go about it or if am wrong plz point me in the right direction. I get my error message to select from dropdown

this is my script below

[php]<?php
error_reporting(E_ALL);

//records shown
$per_page = 10;

//current_page
if (!isset($_GET[‘page’]))
{
$page = 1;
}else
{
$page = $_GET[‘page’];
}

$search = empty($_GET[‘search’])? die ("<font size=‘5’font color=’#FF0E0E’>ERROR: Enter Search Criteria") : mysql_real_escape_string($_GET[‘search’]);
$dropdown = empty($_GET[‘dropdown’])? die ("<font size=‘5’font color=’#FF0E0E’>ERROR: Select from Dropdown") : mysql_real_escape_string($_GET[‘dropdown’]);

//mysql start pagination
if ($page<=1)
$start = 0;
else
$start = $page * $per_page - $per_page;

//Server Variables
$host = “localhost”;
$user = “root”;
$pass = “erhun”;
$db = “books”;

//Open Connection
$connect = mysql_connect($host, $user, $pass) or die (“Unable to connect to host”);

//Select Database
mysql_select_db($db) or die (“Unable to connect to database”);

//Create Query
$sql = “SELECT DISTINCT book_id,call_no,main_title,author1,itm_type,publdate,image,subj1 FROM records WHERE $dropdown LIKE ‘%$search%’ order by publdate” or die (mysql_error());

//how much records returned
@$num_rows = mysql_num_rows(mysql_query($sql));

//no of pages in all
$num_pages = ceil($num_rows / $per_page);

//Append limit for shown records
$sql .= " LIMIT $start, $per_page";

//show all records
$result = mysql_query($sql) or die (mysql_error());

while($row = mysql_fetch_array($result)) {

echo $row[‘main_title’]. “
”;
}

//prev, numbers, next links
$prev = $page - 1;
$next = $page + 1;

echo “


”;

//prev
if($prev > 0)
echo "prev ";

//next
if($page < ceil($num_rows / $per_page))
echo "next ";

?>
[/php]

[code]

SLAM

ONLINE ACCESS CATALOG

Search By... Title Author Subject

[/code]

It’s hard to tell because you’re not showing us everything. I don’t see the html for the dropdrop. Seems like you posted just a small fraction of all the code that’s involved.

I just tested you’re code, I don’t get that error.

I error out after that point on connecting to your MySQL database, since I don’t have that set up on my test machine.

I didn’t say there was an error its just that when i get the first set of results and i click on next, the page 2 and so on is blank. I dont see no results on page 2 till the last. any suggestions on what to do??

Sponsor our Newsletter | Privacy Policy | Terms of Service