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 Link to comment https://forums.phpfreaks.com/topic/101815-solved-displaying-the-last-updated-entry/ 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? Link to comment https://forums.phpfreaks.com/topic/101815-solved-displaying-the-last-updated-entry/#findComment-521009 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"; ?? Link to comment https://forums.phpfreaks.com/topic/101815-solved-displaying-the-last-updated-entry/#findComment-521013 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 Link to comment https://forums.phpfreaks.com/topic/101815-solved-displaying-the-last-updated-entry/#findComment-521045 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" Link to comment https://forums.phpfreaks.com/topic/101815-solved-displaying-the-last-updated-entry/#findComment-521048 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. Link to comment https://forums.phpfreaks.com/topic/101815-solved-displaying-the-last-updated-entry/#findComment-521056 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' Link to comment https://forums.phpfreaks.com/topic/101815-solved-displaying-the-last-updated-entry/#findComment-521058 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. Link to comment https://forums.phpfreaks.com/topic/101815-solved-displaying-the-last-updated-entry/#findComment-521066 Share on other sites More sharing options...
shadiadiph Posted April 19, 2008 Author Share Posted April 19, 2008 works great thanks appreciated Link to comment https://forums.phpfreaks.com/topic/101815-solved-displaying-the-last-updated-entry/#findComment-521263 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 Link to comment https://forums.phpfreaks.com/topic/101815-solved-displaying-the-last-updated-entry/#findComment-521266 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.