Tidus
08-19-2002, 04:35 AM
Hello.
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.
Thanks
firepages
08-20-2002, 07: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
if(!$_GET['from']=0){$from=0;}else{$from=$_GET['from'];}
$perpage=20;
//query to count the pages//
$yaks=mysql_query("SELECT count(id) from $table);
$count=mysql_result($yaks,0);
//number of pages we have in total//
$pages=ceil($count/20);
//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>
etc
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.