SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating a Submit Button to pull next 50 records

    (I originally posted this in the mySQL forum but was told to move it over here ...)

    This is my first time getting data out of a database and I am a little over my head.
    I am extracting 3 fields (id -which is autoincrement primary key, nick & message) and displaying the first 50 records. Where I am stumped is if there are more records I would like to add a submit button where it sends a variable $sent_num (which is the total number of records displayed on this page plus 50) back to the page so that the user sees the next 50 records if they are available. I have commented where I think the code should go, my problem is I am too green to figure out what the best way to do this would be. Any help is appreciated!!!!!

    PHP Code:
    $sent_num=$_POST['sent_num'];

    $num 0;
    $total_num = ($num $sent_num);
    $link mysql_connect(connectinfo is here ...)
       or die(
    'Could not connect: ' mysql_error());
       echo 
    '';
    mysql_select_db('wizzoband'$link);

    $result mysql_query("SELECT * FROM petition WHERE id > ($total_num) AND id < ($total_num + 50) ORDER BY id"$link);

    echo 
    '<table border=0><tr><td>';
    echo 
    '<tr><th>#</th><th>Nickname</th><th>Message</th></tr>';

    while (
    $row mysql_fetch_assoc($result)) 
    {

    echo
    '<tr><td>';
    echo 
    htmlspecialchars(stripslashes($row['id']));
    echo
    '</td><td>';
    echo 
    htmlspecialchars(stripslashes($row['nick']));
    echo
    '</td><td>';
    echo 
    htmlspecialchars(stripslashes($row['message']));
    echo
    '</td></tr>';
    }

    echo 
    '</table>';
    /* need some sort of conditional that says if the total number of rows is greater than the highest id on this page then there is the following option;
    The rest of my (non commented) code works at this point.

    echo '<form name="next" method="post" action="form.php"><input name="sent_num" type="hidden" value="('.$total_num +50).'"><input name="submit" type="submit" value="Get next 50 signatures">
    </form>';
    */ 

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Search this forum for the word/term "pagination"

  3. #3
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    OR

    have a look at this tut.

    http://www.phpfreaks.com/tutorials/43/0.php
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming


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
  •