dachshund Posted November 20, 2012 Share Posted November 20, 2012 Hi, I'm trying to find all the MySQL entries from the last 24 hours. So far I have this. I just don't know how to take 1 day off the current time. $lastday = date('Y-m-d h:i:s'); $sql = "SELECT * FROM content WHERE `live` LIKE '0' AND `date` >= '$lastday' ORDER BY date DESC LIMIT 40"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ Thanks in advance, Jack Quote Link to comment https://forums.phpfreaks.com/topic/270942-find-all-posts-from-last-24-hours/ Share on other sites More sharing options...
AyKay47 Posted November 20, 2012 Share Posted November 20, 2012 (edited) try $sql = "SELECT * FROM content WHERE `live` LIKE '0' AND `date` >= SUBDATE(CURRENT_DATE, 1) ORDER BY `date` DESC LIMIT 40"; Edited November 20, 2012 by AyKay47 Quote Link to comment https://forums.phpfreaks.com/topic/270942-find-all-posts-from-last-24-hours/#findComment-1393791 Share on other sites More sharing options...
Iluvatar+ Posted November 20, 2012 Share Posted November 20, 2012 The 24 hours before will be a dynamic value so it would have to find out on exercution..... [color=#000000][color=#0000BB]<?php [/color][/color] $24HoursAgo = $currentTime-3600*24 [color=#000000][color=#007700]?>[/color][/color] myslq.. SELECT * FROM content WHERE `live` LIKE '0' AND time !> '$24hoursago' ORDER BY date DESC LIMIT 40 Quote Link to comment https://forums.phpfreaks.com/topic/270942-find-all-posts-from-last-24-hours/#findComment-1393793 Share on other sites More sharing options...
Iluvatar+ Posted November 20, 2012 Share Posted November 20, 2012 $24HoursAgo = $currentTime-3600*24 Quote Link to comment https://forums.phpfreaks.com/topic/270942-find-all-posts-from-last-24-hours/#findComment-1393794 Share on other sites More sharing options...
AyKay47 Posted November 20, 2012 Share Posted November 20, 2012 The above post is incorrect and misleading. Until further noted this thread is solved. Quote Link to comment https://forums.phpfreaks.com/topic/270942-find-all-posts-from-last-24-hours/#findComment-1393795 Share on other sites More sharing options...
Iluvatar+ Posted November 20, 2012 Share Posted November 20, 2012 My post? Quote Link to comment https://forums.phpfreaks.com/topic/270942-find-all-posts-from-last-24-hours/#findComment-1393798 Share on other sites More sharing options...
Jessica Posted November 20, 2012 Share Posted November 20, 2012 Yes, your post. What the OP asked for can be done entirely in MySQL, and probably should be. Furthermore, your query uses !> which is invalid syntax. You also used the wrong column name. OP: As an aside, there's no obvious reason to use LIKE on the live column, just compare it with = . Quote Link to comment https://forums.phpfreaks.com/topic/270942-find-all-posts-from-last-24-hours/#findComment-1393858 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.