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.
Limit Entries
Moderator: General Moderators
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.
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.
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.evilcoder wrote:OK no matter what, your going to need to use MySQL and PHP together to get this to work.
Last edited by Kriek on Wed Dec 25, 2002 6:41 pm, edited 2 times in total.