Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: next page thing?
08-19-2002, 04:35 AM #1
- Join Date
- Aug 2002
- Thanked 0 Times in 0 Posts
next page thing?
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, 07:03 AM #2
- Join Date
- May 2002
- Perth Australia
- Thanked 105 Times in 103 Posts
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.
Last edited by firepages; 08-20-2002 at 07:05 AM.
MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)