Re: [PHPLIB] $db->last_record() ??? From: Eric McKeown (ericm <email protected>)
Date: 04/13/00

Christof Beaupoil wrote:

> next_record() of the DB_SQL class works fine. But how do I get the LAST
> record?

> None of those works? Why???
>

Try this:

$last = $db->num_rows() - 1;
$db->seek($last);\

Warning: this is untested code.

>
> Is there any possible way of browsing backwards through the query
> result?
>

I would try this:

$num_rows = $db->num_rows();
$last = $num_rows - 1;

for ($i = $last - 1; $i >= 0; $i--) {
    $db->seek($i);

    $field_value = $db->f("fieldname");
    // Peform any desired processing here.
}

I'm assuming that the database result sets are zero-based, and I'm not sure
if that assumption is correct. If not, that code can be easily modified to
work with 1-based database result sets. A little experimentation should
reveal whether they are zero-based or start at one.

Eric

-
PHP3 Base Library Mailing List. Send messages to <phplib <email protected>>.
To unsubscribe, send "unsubscribe" to <phplib-request <email protected>> in
the body, not the subject, of your message.