Page 1 of 1
Limit Entries
Posted: Wed Dec 25, 2002 1:15 pm
by Kriek
What is an easy way to limit the entries per page of a PHP guestbook without using MySQL?
Currently I have to limit the entries manually (pain in the neck) The entries are added via form.
Posted: Wed Dec 25, 2002 5:03 pm
by zacky
hmm, yea.. I have that problem too..
I selelect * from user
to see all users in my forum.. but there are more than 80 users now..
How can I fix it so there is only, hmm.. 30 users? on each page..
So I can fix, Page 1, 2, 3 and so on..
How can i do that?

Posted: Wed Dec 25, 2002 5:50 pm
by evilcoder
OK no matter what, your going to need to use MySQL and PHP together to get this to work.
Now first off:
on the page you want the entries to limited place this before your guestbook table.
$table = "DB_Table_Name";
$limit = 5; // How many entires per page.
if ($offset == "all") {
$questlist = mysql_query("Your MySQL code here to get the entries out of the DB and how you want them ordered");
}
else if (!isset($offset) || $offset==0) {
$guestlist = mysql_query("Your MySQL code here to get the entries out of the DB and how you want them ordered LIMIT $limit");
}
else {
$l_offset = $offset*$limit;
$guestlist = mysql_query("Your MySQL code here to get the entries out of the DB and how you want them ordered LIMIT $l_offset,$limit");
}
while ($guestbook = mysql_fetch_array($guestlist)) {
$variable = $guestbook["database_field"];
// Change the above to match your database fields
// Just replicate the format to how many fields you have
?>
Put your html code for the guestbooks appearance putting this <?=$variable ?> (Remember, according to what you have above) whereever you want information to be extracted from your database.
<?php
if ($offset != "all") {
$num_result = mysql_query("SELECT * FROM $table");
$num_p = mysql_num_rows($num_result);
@mysql_free_result($num_result);
$p_offset = $offset-1;
if ($offset>0) echo "<div align='center'><a href=\"yourpage.php?offset=$p_offset\">Previous 5</a></div>";
$n_offset = $offset+1;
?>
<?php
if (($offset*$limit) < $num_p || ($offset*$limit+$limit) < $num_p) echo "<div align='center'><a href=\"yourpage.php?offset=$n_offset\">Next 5</a></div>";
} else {
} ?>
There ya go. That should do it. Any questions regarding this i'll answer.
Posted: Wed Dec 25, 2002 6:35 pm
by Kriek
evilcoder wrote:OK no matter what, your going to need to use MySQL and PHP together to get this to work.
There are several PHP Guestbooks that use flatfiles to store entries instead of MySQL and they still limit the entries per page. It just appears everyone is using a different method for the same function.
Posted: Wed Dec 25, 2002 6:38 pm
by evilcoder
ahhh ok. So your guestbook is flatfile. hmmnn. i dont know much about flatfile databases. sorry bout that.
Posted: Wed Dec 25, 2002 6:50 pm
by Kriek
The reason I did not write this Guestbook in PHP/MySQL is because this client does not have access to a database. It would have been so much easier, because I could have wrote it along the same lines as my PHP/MySQL driven shoutbox.
Posted: Wed Dec 25, 2002 7:01 pm
by evilcoder
ohhh rightio. Sorry i couldnt elp. will look into it for you though.
Posted: Thu Dec 26, 2002 9:11 am
by Kriek
Thanks for your help =)