ryanwood4 Posted March 6, 2010 Share Posted March 6, 2010 Hello, How would I delay results by 10 minutes, using the below script. Not sure what I need to add to delay the results. Each result has a datetime called date in the database. <?php $con = mysql_connect("localhost","xxx","xxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xxx", $con); $result = mysql_query("SELECT * FROM members ORDER BY date DESC limit 0,1"); while($row = mysql_fetch_array($result)) { echo '<img class="scaled" src="'.$row['image'].'"/><br />'; echo '<h3><a href="display/'.$row['id'].'">'.$row['title'].'</a></h3>'; } mysql_close($con); ?> Any help is greatly appreciated. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/194348-delaying-database-results/ Share on other sites More sharing options...
Mchl Posted March 6, 2010 Share Posted March 6, 2010 What do you mean by 'delay results by 10 min' Quote Link to comment https://forums.phpfreaks.com/topic/194348-delaying-database-results/#findComment-1022364 Share on other sites More sharing options...
ryanwood4 Posted March 6, 2010 Author Share Posted March 6, 2010 What do you mean by 'delay results by 10 min' Well the script above displays results from the database immediately after they are added, however we want a delay of 10 minutes before results are displayed. Does that make sense? Quote Link to comment https://forums.phpfreaks.com/topic/194348-delaying-database-results/#findComment-1022366 Share on other sites More sharing options...
PFMaBiSmAd Posted March 6, 2010 Share Posted March 6, 2010 I suspect what you actually want is to only retrieve (match) rows WHERE their datetime is more than 10 minutes ago? Rows with a datetime 10 minutes ago or less would not be retrieved? Quote Link to comment https://forums.phpfreaks.com/topic/194348-delaying-database-results/#findComment-1022370 Share on other sites More sharing options...
ryanwood4 Posted March 6, 2010 Author Share Posted March 6, 2010 I suspect what you actually want is to only retrieve (match) rows WHERE their datetime is more than 10 minutes ago? Rows with a datetime 10 minutes ago or less would not be retrieved? That's a better way of putting it! That's exactly what I want to do. Quote Link to comment https://forums.phpfreaks.com/topic/194348-delaying-database-results/#findComment-1022371 Share on other sites More sharing options...
inversesoft123 Posted March 6, 2010 Share Posted March 6, 2010 you can delay it by 10 mins. $resulttime = time() - $resultold[1]; $result = mysql_fetch_array(mysql_query("SELECT * FROM members WHERE time='$resulttime' ORDER BY date DESC limit 0,1")); Quote Link to comment https://forums.phpfreaks.com/topic/194348-delaying-database-results/#findComment-1022372 Share on other sites More sharing options...
ryanwood4 Posted March 6, 2010 Author Share Posted March 6, 2010 you can delay it by 10 mins. $resulttime = time() - $resultold[1]; $result = mysql_fetch_array(mysql_query("SELECT * FROM members WHERE time='$resulttime' ORDER BY date DESC limit 0,1")); Don't seem to be getting any results with that? Quote Link to comment https://forums.phpfreaks.com/topic/194348-delaying-database-results/#findComment-1022376 Share on other sites More sharing options...
PFMaBiSmAd Posted March 6, 2010 Share Posted March 6, 2010 That's because that query does not address what you stated. What type of values are in your date column? Quote Link to comment https://forums.phpfreaks.com/topic/194348-delaying-database-results/#findComment-1022378 Share on other sites More sharing options...
ryanwood4 Posted March 6, 2010 Author Share Posted March 6, 2010 That's because that query does not address what you stated. What type of values are in your date column? The format is (example): 2010-02-28 12:17:37 Quote Link to comment https://forums.phpfreaks.com/topic/194348-delaying-database-results/#findComment-1022381 Share on other sites More sharing options...
inversesoft123 Posted March 6, 2010 Share Posted March 6, 2010 If you have date — Format a local time/date time field in table. http://www.php.net/manual/en/function.date.php Quote Link to comment https://forums.phpfreaks.com/topic/194348-delaying-database-results/#findComment-1022383 Share on other sites More sharing options...
PFMaBiSmAd Posted March 6, 2010 Share Posted March 6, 2010 You would need a WHERE clause in your query - WHERE date < DATE_SUB(NOW(),INTERVAL 10 MINUTE) Quote Link to comment https://forums.phpfreaks.com/topic/194348-delaying-database-results/#findComment-1022388 Share on other sites More sharing options...
ryanwood4 Posted March 6, 2010 Author Share Posted March 6, 2010 You would need a WHERE clause in your query - WHERE date < DATE_SUB(NOW(),INTERVAL 10 MINUTE) Work's perfectly! Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/194348-delaying-database-results/#findComment-1022392 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.