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
a simple query
Moderator: General Moderators
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
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
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
SELECT foo FROM bar ORDER BY id DESC, LIMIT 1i knew that it is so easy to you , how didn't i think...feyd wrote:Code: Select all
SELECT foo FROM bar ORDER BY id DESC, LIMIT 1