hi i have a table i can write to it ok but i need to know the correct syntax to retrieve the last updated record i have been using something like this but it doesn't work.??


$sql = "select * from tblexdetails where intexchangeID='$tid'";

can anyone ive me any pointers the above only shows the record from a sinlgle line table entry. The table in question has a dtUpdatedOn column

Recommended Answers

All 4 Replies

If you want to view the last updated record and you have a column which stores the last update. Then use this :
(i am assuming that you have stored time in unix timestamp format, i.e you have used php's time() function)

$sql = "SELECT * FROM tblexdetails where  dtUpdatedOn= (SELECT max(dtUpdatedOn) FROM tblexdetails);";

Also, assuming that there is a unique ID field there is an easier way. You can simply do a query like this:

SELECT *
FROM `tblxdetails`
ORDER BY `id` DESC
LIMIT 1 ;

and it will give you the last added field only Though this will only get you the last one added, if there is editing of records going on then use the previous code given.

Hope that helps,
Sam

Also, assuming that there is a unique ID field there is an easier way. You can simply do a query like this:

SELECT *
FROM `tblxdetails`
ORDER BY `id` DESC
LIMIT 1 ;

and it will give you the last added field only Though this will only get you the last one added, if there is editing of records going on then use the previous code given.

Hope that helps,
Sam

thanxs great the latter works great the 1st comes up with an sql error

Hmm the query seems to work fine here...

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.