Jump to content

[SOLVED] displaying the last updated entry


shadiadiph

Recommended Posts

Hi I have a small problem I have tried numerous ways but can't get it to work.

I have the following script as the head to select from my database there is a dtUpdatedOn column in tbleexdetails how do i get it to display the last updated row in the table?

 

 

 

$treid = $_GET["tid"];

$sql = "select * from tblexdetails where intexID='$treid'";

$temps=$DB_site->query($sql);

if($row=$DB_site->fetch_array($temps))

 

 

This has been driving me nuts for 3 days now i have tried using order by many things but can't seem to get anything to work any hints would be most appreciated Thank you

 

 

 

yes dtUpdatedOn is a time the format is in the insert it is set as .date("Y-m-d") in the database it records as 2008-04-19 00:00:00

 

 

 

yes i tried Code: $sql = "select * from tblexdetails where intexID='$treid' ORDER BY `intexID` DESC"; doesn't work

While there may be a way to do it with your date formatted that way, I don't know it myself, so I can't help you with that. But I can give you an alternative suggestion that I use. I keep all timestamps in my database as unix timestamps - the number of seconds since jan 1, 1970. You can get this using time() and mktime(). Then when you want to check the most recently updated row, you can use:

 

"SELECT row_id FROM tblexdetails  ORDER BY row_id DESC LIMIT 1"

I just made up 'row_id'. Change it to whatever the column name is of the data you want to get from the database. If there is more than one column name, separate them by commas.

 

Or you could use * like you were before, but thats not very good programming.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.