...

View Full Version : Displaying a table with the next row of data



Fishhead
01-26-2010, 06:58 AM
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?

Len Whistler
01-27-2010, 04:04 AM
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

$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>";
}

Fishhead
01-27-2010, 04:06 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum