shadiadiph Posted April 19, 2008 Share Posted April 19, 2008 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 Quote Link to comment Share on other sites More sharing options...
haku Posted April 19, 2008 Share Posted April 19, 2008 is dtUpdatedOn a time? And if so, what time format is it in? Quote Link to comment Share on other sites More sharing options...
stuffradio Posted April 19, 2008 Share Posted April 19, 2008 Did you try something like: $sql = "select * from tblexdetails where intexID='$treid' ORDER BY `intexID` DESC"; ?? Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted April 19, 2008 Author Share Posted April 19, 2008 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 Quote Link to comment Share on other sites More sharing options...
haku Posted April 19, 2008 Share Posted April 19, 2008 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" Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted April 19, 2008 Author Share Posted April 19, 2008 I can't seem to get that to work i just tried changing my date stamp to .date("Y-m-d h:m:s") so it records the exact time but no luck just can't seem to get it working. Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted April 19, 2008 Author Share Posted April 19, 2008 here is the error i get from your solution "SELECT row_id FROM tblexdetails ORDER BY row_id DESC LIMIT 1" Unknown column 'row_id' in 'field list' Quote Link to comment Share on other sites More sharing options...
haku Posted April 19, 2008 Share Posted April 19, 2008 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. Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted April 19, 2008 Author Share Posted April 19, 2008 works great thanks appreciated Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted April 19, 2008 Author Share Posted April 19, 2008 sorry worked better than be 4 but still have an error shall revert more tomorrow not in any condition to make any sense this saturday niht sorry Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.