Jump to content

Pagination


ItsWesYo

Recommended Posts

I have seen several PHP pagination tutorials and such... but none seem to "fit" in with this:

 

<?php
$host = "localhost";
$user = "xxxx";
$pass = "xxxx";
$db = "xxxx";

mysql_connect($host, $user, $pass) OR die ("Guestbook is temporarily offline.");
mysql_select_db($db) OR die("Guestbook is temporarily offline.");

$name = stripslashes($_POST['txtName']);
$message = stripslashes($_POST['txtMessage']);

if (!isset($_POST['txtName'])) {

    $query = "SELECT id, name, message, DATE_FORMAT(date,'%m/%d/%y') as newdate FROM guests ORDER BY id DESC";
    $result = mysql_query($query);
    
    while ($row = mysql_fetch_object($result)) {

?>

<b>#<?php echo $row->id; ?> - Posted by <?php echo $row->name; ?> on <?php echo $row->newdate; ?></b><br>
<?php echo $row->message; ?><br><br>

<?php
        
    }
    
?>

<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">

<b>Name:</b><br>
<input type='text' name='txtName' class='other'><br><br>

<b>Message:</b><br>
<textarea name='txtMessage' class='other'></textarea><br><br>
    
<input type='submit' value='Add' class='other'>
    
</form>

<?php

}

else {

    // Adds the new entry to the database
    $query = "INSERT INTO guests SET message='$message', name='$name', date=NOW()";
    $result = mysql_query($query);

    // Takes us back to the entries
    $ref = $_SERVER['HTTP_REFERER'];
    header ("Location: $ref");
}
?> 

 

Help? :P

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

That is about as clear as mud. A little more detail as to what your trying to accomplish would be helpful.

 

I assume that your wanting pagination on this section of code...

 

if (!isset($_POST['txtName'])) {

    $query = "SELECT id, name, message, DATE_FORMAT(date,'%m/%d/%y') as newdate FROM guests ORDER BY id DESC";
    $result = mysql_query($query);
    
    while ($row = mysql_fetch_object($result)) {

 

Why do you say that the tutorials don't "fit" in with this code?

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/59030-pagination/#findComment-293051
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.