Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2009
    Location
    McKinleyville, CA
    Posts
    40
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Displaying a table with the next row of data

    I have searched for hours and resigned myself to asking here for a solution.

    I am working on a webpage that will record commercial fishermens landings. Each fisherman will have a username and password. He can login to view his account. Government monitors will enter landings data. The fisherman would like to see a table that display the fish caught for each delivery. Each delivery is stored in a mysql data base as a row. When a fisherman logon to the site, his username becomes session variable that filters his landing records.

    I have construct the table to display the landing. I have place a button label next on the page that passes to a second page which is identical in appearance, but here the code seeks the next higher landing record for that fisherman. On this second page, repeated clicks on the Next button will advance through the records showing all of the deliveries. This all works fine. But if the Next button is continued to be clicked, and there are no more records, only a blank page (with labels) is displayed.

    How can I stop that advance through the records at the last record found?

  • #2
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Quote Originally Posted by Fishhead View Post
    I have place a button label next on the page that passes to a second page which is identical in appearance, but here the code seeks the next higher landing record for that fisherman.
    This is where you make some changes:
    • I recommend you post to the same page using the $_GET method.
    • You will need a 2nd query to get the next record. This may be tricky, it depends on how the DB is setup. You might even get it from the original query.
    • You can also add previous links using the same method.




    Below is the code I use, but it's been edited for this post and there may be syntax errors.

    index.php
    PHP Code:
    $id = isset($_GET['id']) ? $_GET['id'] : 1//Defaults to 1 

    $result mysql_query("SELECT * FROM ads WHERE id = '$id'");
    $row mysql_fetch_row($result);

    // Display records.

    // retrieve next record for NEXT link
    $date $row[date];
    $n mysql_query("SELECT id FROM ads WHERE date > '$date' ORDER BY date ASC LIMIT 1");
    $next mysql_fetch_row($n);

    //  Next link only appears if record is present. Could use isset also.
    if ($next[0] >= 1) {
    echo 
    "<a href=\"index.php?id=$next[0]\">Next</a>";

    Leonard Whistler

  • #3
    New Coder
    Join Date
    Aug 2009
    Location
    McKinleyville, CA
    Posts
    40
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Len, once again thanks for the response. I was able to bring things together yesterday. It may not be the most elegant code but it does seem to work.

    I ended up with first page that would display the first landing in the database. If there was no landing made yet for that idividual, the table is blank.

    I also add two other pages, one for incrementing to the next landing and one for going backwards. I used MAX and MIN to set the bounds and with a series of if/elseif statements allowed the NEXT or BACK button to be either active if the current page was within the max/min or disabled if it was at the boundary.

    I also used a SELECT COUNT to know the total number of records, so I can display the current page number out of the total ( Delivery 3 out of 27). Going forward (NEXT) adds one, while going BACK subtracts one from the display.

    It turned out not to be as difficult as I was making it be, and as usual, syntax is where most of my problems occur.

    Pete


  •  

    Posting Permissions

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