View Full Version : next page thing?
08-19-2002, 05:35 AM
I have a page that lists all the news headlines i have made, but i want it to show 20 on a page and then have the option to click next page and show the next 20.
anyone know how this is done.
08-20-2002, 08:03 AM
you are probably using MySQL3.* in which case you have to make 2 queries...
1 to find out how many 'pages' you have & one to fetch $x pages worth of content for this page which you do using LIMIT
//query to count the pages//
$yaks=mysql_query("SELECT count(id) from $table);
//number of pages we have in total//
//query for thispage data//
$yaks=mysql_query("SELECT * FROM $table LIMIT $_GET[from],$perpage);
not going into details but now you build your pages menu and you would normally construct this in a loop... //for $x=0;$x<$pages;$x++ ..... etc to create...
<a href="<?=$_SERVER['PHP_SELF']?from=0">page 1</a>
<a href="<?=$_SERVER['PHP_SELF']?from=20">page 2</a>
thats the basics of it anyway, with MySQL 4 (if ever released as stable) - you can alledgedly do this...
$sql = "Select SQL_CALC_FOUND_ROWS,* from $table limit 0,20";
which returns not only your first 20 rows, but also the count of all rows, not that I have tried it but thats whats supposed to happen.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.