how to fetch last recodset from database in php


#1

hi
i want to know that how to fetch last record available in database or the last sequence number(e.g if autonumber is on and the records are not in any order then how to fetch the last squence)


#2

Well, do you mean you have a table with a field that you want the highest or lowest value of?
That would depend on the field you are talking about. There are tons of ways to sort values of fields.
Tell us what the current SQL query is and which field in it your want the highest of…

This is basically a SQL question and should be simple. Just need to know a little about the table and field you want to get the last of…


#3

i mean that
e.g

reg# first name last name email
1 abc xyz 123@abc.com
6 xyz abc 456@xyz.com
3 aaa bbb aabb@xxyy.com

so my question is that in the above order the data is stored in dbase
so how to get the latest reg# like in above example is 6 as its not the first record nor last record
should i first have to sort and then get the last record or is there any way to get that latest record without sorting

and

also how to get the last record
as i m using mysql_fetch_array() function to get record


#4
hello mohsin1122, to fetch last record available in database. use below query for fetch record replace tablename with your database table. replace reg with your field name

SELECT * FROM tablename ORDER BY reg DESC LIMIT 1;

I hope this will helpful for you.
SR


#5

Thats it
Thanks Sarthak Patel Bro


#6
it's nice that your problem solve. keep posting more issues and receive fast and correct solution. ~~sr~~