last row

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

last row

Post by hob_goblin »

how would i return the LAST row of table?
kaizix
Forum Commoner
Posts: 50
Joined: Tue Jun 18, 2002 9:16 pm
Location: california
Contact:

Post 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
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Try this:

Code: Select all

SELECT field1, field2, field3 FROM table ORDER BY id DESC LIMIT 1
Mac
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

@kaizix:
fetch_row returns the data of a single row. The array-elements are the columns of that row.
kaizix
Forum Commoner
Posts: 50
Joined: Tue Jun 18, 2002 9:16 pm
Location: california
Contact:

Post 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
Post Reply