SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru adammc's Avatar
    Join Date
    Aug 2004
    Location
    Cairns, Australia
    Posts
    762
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Help needed PLEASE

    Hi,
    I want to split my guestbook entries onto different pages (limit 5 entries per page).
    I have searched google and couldnt find an easy way to modify my code to accomodate for this.

    Can anyone help?


    <?
    //the host, name, and password for your mysql
    mysql_connect("localhost","user","pass");

    //select the database
    mysql_select_db("epidemic_guestbook");

    if($submit)
    {
    //use the PHP date function for the time

    $offset = 3600*10;
    $time = gmdate("dS F Y, G:i", time() + $offset);

    // inserting it into the shoutbox table which we made in the mysql statements before
    $result=MYSQL_QUERY("INSERT INTO shoutbox (id,name,message,time)".
    "VALUES ('NULL','$name', '$message','$time')");
    }
    ?>

    <?
    //returning the last 5 messages
    $result = mysql_query("select * from shoutbox order by id desc limit 5");

    //the while loop
    while($r=mysql_fetch_array($result))
    {
    //getting each variable from the table
    $time=$r["time"];
    $id=$r["id"];
    $message=$r["message"];
    $name=$r["name"];
    ?>

    <b>Posted by/b>&nbsp;<font color="red"><? echo $name?></font><br>
    <b>Date/b>&nbsp;<? echo $time?><br>
    <b>Message/b><br>
    <? echo wordwrap($message, 50, '<br>',1)?><br><br><br>
    <? }?>

  2. #2
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try :

    PHP Code:

    <? 
    //returning the last 5 messages 
    $query "select * from shoutbox order by id desc limit 5"
    $result mysql_query($query);
    //the while loop 
    while($r=mysql_fetch_array($result)) 

    //getting each variable from the table 
    $time=$r["time"]; 
    $id=$r["id"]; 
    $message=$r["message"]; 
    $name=$r["name"]; 
    }
    ?>
    Not sure, but this may work!

  3. #3
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, i forgot, normally I would use

    PHP Code:

    $time
    =$r['time'];  //single quotes 
    and not

    PHP Code:

    $time
    =$r["time"];  //double quotes 
    Dont think this would make it not work though!

    also you might want to change :

    PHP Code:

    $query 
    "select * from shoutbox order by id desc limit 5"
    to use capitals

    PHP Code:

    $query 
    "SELECT * FROM shoutbox ORDER BY id DESC LIMIT 5"
    Again I dont know if this would make it not work.


  4. #4
    SitePoint Enthusiast rramroop's Avatar
    Join Date
    May 2003
    Location
    UK
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    search for "pagination" in this forum and on google. That's how I learned how to do it :-)

    Cheers


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •