Hi,

Has anyone seena script for searching a database, and having pagination as well...as I have tried and successfully created a search database sarch webpage..and a pagination webpage, but that returns all the data in the database...

Regards

Rob Wood

Try writing one yourself. They aren't too tricky.

1) use mysql_num_rows to get the number of rows.

2) in your while loop put a counter that only echos results within the range you want. 1-10, 11-20, 21-30 etc

3) pass the "starting" count in each pagination link

Here some code I wrote a while back

$avails=mysql_query($qry) or die (mysql_error());
$total=mysql_num_rows($avails);
if (!$page) $page=1;
$limit = ($page * 10);
$count = $limit - 10;


while ($avail_array=mysql_fetch_array($avails))
{
if ($i > $count && $i <= $limit) {
//echo your stuff
}
}


$paging=0;
$j=1;
while ($paging <= $total) {
if ($page != $j ) {
echo "<a href=\"".$PHP_SELF.
"?queryinfoyoumightneed=xyx&page=$j\">$j</a>";
} else echo "<b>".$j."</b>";


echo "&nbsp;&nbsp;&nbsp;";
$j++;
$paging=$paging + 10;
}

Now you probably should adjust the mysql query to use the limit function to make the code optimized...

SELECT * FROM table LIMIT 5,10; # Retrieves rows 6-15

Edited 3 Years Ago by happygeek: fixed formatting

I search it too
helo everybody who have this code, share here please

Hi,

Has anyone seena script for searching a database, and having pagination as well...as I have tried and successfully created a search database sarch webpage..and a pagination webpage, but that returns all the data in the database...

Regards

Rob Wood

or else changing the limit of your query on runtime and forming the query like
'select * from tablename where fieldID=something && other conditions limit $start, $pagesize'
Now in the above code $pagesize can be 10 if you want to display 10 rows and so on.
$start=0 initially and then it increases to 11 for second page, for page 3 as 21 and for page 4 as 31 etc.
These values you can set by checking what buttons value you getting in post.

This article has been dead for over six months. Start a new discussion instead.