Next Page Button [on hold]
So I want to make a simple shoutbox using MySQL and PHP and I know enough
of both languages to produce it rather easily. Also I know how to limit it
to only show the last 5-10 or whatever comments at a time. However, what
would be the process of making it so the shoutbox only shows the last 5
comments and then there is a button that says "Older Comments" and it
shows the next 5 and so on and then another button that says "Newer
Comments" and it goes back a page. I'm not quite sure how I would go about
doing that without writing tons and tons of code.
Here is the code I have for my shoutbox:
addmessage.php
<?php
include("config.php");
if ($_POST['shoutname'] and $_POST['shout'] !== " ") {
if (isset($_POST['shoutname'])) {
$shoutname = mysql_real_escape_string($_POST['shoutname']);
$shout = mysql_real_escape_string($_POST['shout']);
mysql_query("INSERT INTO shoutbox (name, shout) VALUES
('$shoutname','$shout')");
mysql_close($bd);
}
}
header("Location: shoutbox.php");
?>
(config.php contains my mysql connection information)
shoutbox.php
<?php
include("config.php");
$data = mysql_query("SELECT * FROM shoutbox ORDER BY id DESC LIMIT 5");
while ($info = mysql_fetch_array($data)) {
echo $info['name']. "<br>";
echo $info['shout']. "<br>";
}
?>
<form method="post" action="addmessage.php">
Name: <input type="text" name="shoutname" /><br />
Message: <input type="text" name="shout" />
<input type="submit" />
</form>
I'm just not sure how to make a button that shows the next five comments
ordered by id and so on.
No comments:
Post a Comment