Page 1 of 1

a simple query

Posted: Sun Feb 18, 2007 5:28 am
by siyaco
i have a table which includes userid(auto increment), username, message

i want to write a query which selects the name and message from the row has the biggest id
and then i want to give the values of that name and message into two variables with php
how can i do?
thanks all in advance

Posted: Sun Feb 18, 2007 6:48 am
by siyaco
i have just solved the problem, may be it is easy to you but again i am writing what i did

1- $query='SELECT name, message FROM table_name where id=(SELECT max(id) from table_name)'

2-$line=mysql_fetch_array($query, MYSQL_NUM);
echo $line[0]; // gives the name
echo $line[1]; // gives the message


thanks all in advance

Posted: Sun Feb 18, 2007 7:52 am
by feyd

Code: Select all

SELECT foo FROM bar ORDER BY id DESC, LIMIT 1

Posted: Sun Feb 18, 2007 10:31 am
by siyaco
feyd wrote:

Code: Select all

SELECT foo FROM bar ORDER BY id DESC, LIMIT 1
i knew that it is so easy to you , how didn't i think... :D