hellonoko Posted April 28, 2009 Share Posted April 28, 2009 I am trying to write a query that selects all rows entered less than a day ago by comparing the field that states when the row was created against the current date/time minus 1 day. What is the proper way to do this as my query is failing. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home2/sharingi/public_html/scrape/display/display.php on line 167 <?php $current_time = strtotime("now"); //take one day in seconds from the current time to find the timestamp for 24 hours ago $day_old = $current_time - 86400; //change timetamp to a date format to compare $day_old = date("Y-m-d H:i:s", $day_old); echo $day_old; // select all entries that are less than the 1 day old $query = mysql_query("SELECT * FROM `mp3links` WHERE `foundtime` < $day_old AND `scraped` != '0' ORDER BY `foundtime` DESC"); ?> Link to comment https://forums.phpfreaks.com/topic/155945-solved-query-trying-to-select-all-rows-less-than-1-day-old-using-date-field/ Share on other sites More sharing options...
Mchl Posted April 28, 2009 Share Posted April 28, 2009 Query fails for some reason. Try displaying mysql error message $query = mysql_query("SELECT * FROM `mp3links` WHERE `foundtime` < $day_old AND `scraped` != '0' ORDER BY `foundtime` DESC") or die(mysql_error()); to see why Link to comment https://forums.phpfreaks.com/topic/155945-solved-query-trying-to-select-all-rows-less-than-1-day-old-using-date-field/#findComment-820909 Share on other sites More sharing options...
mtoynbee Posted April 28, 2009 Share Posted April 28, 2009 Need single quotes around date in sql query $query = mysql_query("SELECT * FROM `mp3links` WHERE `foundtime` < '".$day_old."' AND `scraped` != '0' ORDER BY `foundtime` DESC") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/155945-solved-query-trying-to-select-all-rows-less-than-1-day-old-using-date-field/#findComment-820913 Share on other sites More sharing options...
hellonoko Posted April 28, 2009 Author Share Posted April 28, 2009 Nice. Thanks. Link to comment https://forums.phpfreaks.com/topic/155945-solved-query-trying-to-select-all-rows-less-than-1-day-old-using-date-field/#findComment-820922 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.