Page 1 of 1

last row

Posted: Fri Jun 21, 2002 1:16 am
by hob_goblin
how would i return the LAST row of table?

Posted: Fri Jun 21, 2002 2:49 am
by kaizix
well, if there's an id, you can order by id desc and then it would become the first row....

or you use the (is using mysql) mysql_fetch_row

Code: Select all

$number = mysql_num_rows($connection);
$row = mysql_fetch_row($connection);
$rowї$number]; //being the last row

Posted: Fri Jun 21, 2002 6:20 am
by hob_goblin
that doesn't work completely right...

here is the thing:

they are natural numbers, and the closest idea i've gotten was to sort them in descending order, and grab the first row using "limit" or something like that, then using it's # and adding 1...

could someone try to put that idea into code? I don't know how to use 'limit', and couldn't find any tutorials on it

Posted: Fri Jun 21, 2002 6:32 am
by twigletmac
Try this:

Code: Select all

SELECT field1, field2, field3 FROM table ORDER BY id DESC LIMIT 1
Mac

Posted: Fri Jun 21, 2002 6:42 am
by volka
@kaizix:
fetch_row returns the data of a single row. The array-elements are the columns of that row.

Posted: Fri Jun 21, 2002 6:45 am
by kaizix
oh, right....i know there was something i was thinking about when i posted that....now where is it...

[edit]

well, actually, it'd still be ok since it'd fetch the first row ( which is what i think i was thinking)...just needed the field number in place of $number