bryanptcs Posted November 8, 2006 Share Posted November 8, 2006 I have a simple php form that post information to a mysql database. Below the form it lists all the posts that have been made, with the name of the person, time, date, and message. It is a modified guestbook to be more like just a quick comment post. What I want to know is if there is a way to write into the php code to have it only post 10 comments per page, and then have a clickable button to go to the next page. I will include my code minus the db login. Any suggestions would be great:<?php/** * Create the table in your MySQL database: * * CREATE TABLE guests ( * id int(10) NOT NULL auto_increment, * name varchar(50) NOT NULL, * message varchar(255) NOT NULL, * date timestamp(14) NOT NULL, * PRIMARY KEY (id) * ) * * Change the database login settings to your own * * The script is now ready to run */// Change these to your own database settings$host = "";$user = "";$pass = "";$db = "";mysql_connect($host, $user, $pass) OR die ("Could not connect to the server.");mysql_select_db($db) OR die("Could not connect to the database."); $name = stripslashes($_POST['txtName']);$message = stripslashes($_POST['txtMessage']);$rate = stripslashes($_POST['rate']);if (!isset($_POST['txtName'])) { $query = "SELECT id, name, rate, message, DATE_FORMAT(date, '%D %M, %Y at %H:%i') as newdate FROM guests ORDER BY id DESC"; $result = mysql_query($query); while ($row = mysql_fetch_object($result)) {?><p class="infotext"><?php echo $row->message; ?><br />Rating: <?php echo $row->rate; ?> </strong><br /><span class="form2">Posted by <?php echo $row->name; ?> on <?php echo $row->newdate; ?></span></p><?php } ?><?php}else { // Adds the new entry to the database $query = "INSERT INTO guests SET message='$message', name='$name', date=NOW(), rate='$rate'"; $result = mysql_query($query); // Takes us back to the entries $ref = $_SERVER['HTTP_REFERER']; header ("Location: $ref");}?> Link to comment https://forums.phpfreaks.com/topic/26619-create-pages-with-mysql-database-output/ Share on other sites More sharing options...
blear Posted November 8, 2006 Share Posted November 8, 2006 $beginMessage = 0;$endMessage = 10;SELECT id, name, rate, message, DATE_FORMAT(date, '%D %M, %Y at %H:%i') as newdate FROM guests ORDER BY id DESC LIMIT $beginMessage,$endMessagewhere each time you hit the next_10 button, it sends new values for $beginMessage and $endMessage, incrementing each by ten. Link to comment https://forums.phpfreaks.com/topic/26619-create-pages-with-mysql-database-output/#findComment-121751 Share on other sites More sharing options...
bryanptcs Posted November 8, 2006 Author Share Posted November 8, 2006 Ok, I have the code to where it only displays X amount at a time, but how do I get the next button to work correctly? Link to comment https://forums.phpfreaks.com/topic/26619-create-pages-with-mysql-database-output/#findComment-121759 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.