tags:

views:

38

answers:

2

Currently I fetch rows with the help of mysql_fetch_array() (and the LIMIT/OFFSET) (ie. while ($row = mysql_fetch_array($res)) { ... }); but the last row is not needed as it was to be fetched in order to make sure there is at least one more row left - it is not for display.

+1  A: 

You can simply get the number of rows before this loop:

select count(*) from <your_table> WHERE <your_condition>;

Then, you can exclude the last record within the loop using a counter. Is this what you want??

Khaled
A: 

You should not mix presentation with logic anyway. Fetch all the rows in an array:

$rows = array();

while ($row = mysql_fetch_array($res)) {
    $rows[] = $row;   
}

and delete the last one:

array_pop($rows);

Or just set LIMIT to get one less of that is possible.

Update:

Here is another possibility using a for loop and mysql_num_rows:

for($i = mysql_num_rows($res) - 1; $i--; $row = mysql_fetch_array($res))

but the first one is more readable imo.

Felix Kling
I think the option of setting LIMIT to get one less is not possible, as @Gore needs to be certain that there is at least one more row. But the array_pop($rows) seems like the way to go.
Richard Fawcett