Jump to content

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 ?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.