SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
-
Jun 12, 2007, 09:05 #1
php/ mysql - help with pagination
I have created a simple cms and I need to have an archive page that shows ten articles per page, with a "< next | previous >" pagination system or similar.
I have spent a long time away from php, and would dearly love it if somebody could show me how to do it, here is what I have now;
PHP Code:<?php
include "admin/dbconnect.php";
include "includes/format_date.php";
$result = mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT 0,5");
//echo's the articles, and even properly indents the code
while($row = mysql_fetch_array($result))
{echo "
<p><em>".$row['shortdescr']."</em></p>
<p>".$row['title']."</p>
<p>".$row['source']."</p>
<p><strong>Posted on:</strong> ".$row['date']."</p>
<hr />
";
}
mysql_close($conn);
?>
-
Jun 12, 2007, 09:44 #2
- Join Date
- Jul 2002
- Location
- In the network.
- Posts
- 217
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Pull your page number into the script and use that to populate your pagination controls and to calculate your "LIMIT" in your SQL query.
-
Jun 12, 2007, 11:40 #3
- Join Date
- Jun 2007
- Posts
- 45
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The idea of pagination is that your code will calculate the maximum number of pages and then on each page will return the query with the LIMIT clause, that is set by the page number.
I wrote a class, it is not OOP it is a beginner class, it is very simple.If you want i will post-it, a search will also help you with this issue.
-
Jun 13, 2007, 02:18 #4
-
Jun 13, 2007, 02:42 #5
- Join Date
- Dec 2006
- Location
- /dev/swat
- Posts
- 619
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This is simple script u will find it helpful.
http://www.codewalkers.com/c/a/Link-...de/Pagination/
-
Jun 13, 2007, 02:57 #6
Thank you for the link, I've just found this one too, which works for me: http://www.phpfreaks.com/tutorials/73/0.php
Bookmarks