954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

search and pagination

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

wood1e
Newbie Poster
6 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

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 "$j";
} else echo "".$j."";

echo "   ";
$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

barnamos
Junior Poster in Training
50 posts since Mar 2005
Reputation Points: 15
Solved Threads: 0
 

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
mylove
Newbie Poster
1 post since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

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.

network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You