0

Hi, anyone know how i can find the last added entry in mysql db.
i am aware of: mysql_insert_id(), this function returns the last id but
I need to select the last row where $username = username.

3
Contributors
8
Replies
11
Views
6 Years
Discussion Span
Last Post by crishlay
0

what exactly is last row ?

When you store records in database , it is not necessary that the last entered row will be always stored at the bottom of the table.

0

sorry, i didnt explain myself clearly.
i need to find the ID of the last row where the column USERNAME matches $username.

ID is auto increment.

0

I dont know how but ill figure it out if you think it will work.
bare in mind that the last row ,or the row with the highest ID might not be the correct row, it must match the username as well, as there couldve been other records to the same table from different users. ill check MAX(ID) out so long.
Thanks bud

0

try something like this

select max(id), name
from table_name
group by id
having name = 'NAME'
order by id
0

to debasisdas: Thanks bud
Now i get max(id).

I used what you gave me but changed it to the following:

mysql_query("SELECT max(id) FROM user_record WHERE user = '".$finduser['id']."' ") or die(mysql_error());

It does work but i dont understand why you used "name" and "having" in the instruction.
Appreciate your time!

0

use SELECT @LastID = SCOPE_IDENTITY()
RETURN 0;
in stored procedure for returning last value of ID

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.