Jump to content

$result returning too many rows for pagination ?


Vertaxe

Recommended Posts

Hi guys,

I have a search bar which looks at 3 mysql fields and returns results if there are any matches, and it seems to work, however my pagination is messing around, I can't quite work out why. It thinks there are thousands of rows, when there should only be a few... !

 

Here is a snippet from my pagination_process.php which is where I think the problem lies.

$result = mysql_query("
SELECT * 
FROM table 
WHERE field1 LIKE \"%$search%\" 
OR field2 LIKE \"%$search%\" 
OR field3 LIKE \"%$search%\" 
");
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];

$rows_per_page = 4;
$lastpage = ceil($numrows/$rows_per_page);


$pageno = (int)$pageno;
if ($pageno > $lastpage) {
   $pageno = $lastpage;
} 
if ($pageno < 1) {
   $pageno = 1;
} 

$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;

 

Any help is muchly apreciated :)

$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];

Those two lines of code fetch the first row form the result set and assign the value from the first column in your table to $numrows. Perhaps you intended to use mysql_num_rows ?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.