Jump to content

[SOLVED] Pagination


matthew798

Recommended Posts

Hello again.

 

How would i set up a pagination that displays only 5 rows?

 

<?php
$counter = 5;

mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());


$result = mysql_query("SELECT * FROM news ORDER BY id DESC") 
or die(mysql_error());  

echo "<table border=0 width=696>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {

echo "<tr><td><span class='title'>"; 
echo $row['title'];
echo "</span></td></tr><tr><td><span class='date'>"; 
echo $row['date'];
echo "</span></td></tr><tr><td><hr class='hrnews'></td></tr><tr><td><span class='body'>"; 
echo $row['body'];
echo "</span></td></tr>"; 
}
echo "</table>";
?>

Link to comment
https://forums.phpfreaks.com/topic/123532-solved-pagination/
Share on other sites

lol I was just getting ready to respond with the limit 5 part.

 

Something I like to do when setting up pages like that is actually pull 1 extra row from the database and use that extra row to determine whether or not i need to put the next button on the page or not. There's probably a better way to do this, but that works for me  :)

Link to comment
https://forums.phpfreaks.com/topic/123532-solved-pagination/#findComment-637997
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.