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.

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.

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.

then why not use MAX(ID)

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

try something like this

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

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!

Read books to learn more.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.