timmah1 Posted June 1, 2009 Share Posted June 1, 2009 This query returns 0 results, even though there are 9 dates between the two. Can anybody tell me why? <?php $sql = "SELECT * FROM lunch WHERE person = '".$_GET['id']."' AND date BETWEEN '".date("Y-m-d")."' AND '".date("Y-m-d", strtotime("+ 7 Days"))."'"; $result = mysql_query($sql); $numrows = mysql_num_rows($result); if($numrows == 0 ){ echo "No lunch for $p1 entered right now"; } ?> Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/160538-solved-select-between-dates/ Share on other sites More sharing options...
Maq Posted June 1, 2009 Share Posted June 1, 2009 Try: AND date > DATE_SUB(NOW(), INTERVAL '1' WEEK) Have you echoed out your query to see what's actually being passed? Have you checked to see if your query died? $result = mysql_query($sql) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/160538-solved-select-between-dates/#findComment-847237 Share on other sites More sharing options...
roopurt18 Posted June 1, 2009 Share Posted June 1, 2009 I'm not telling you anything until you properly escape your database inputs: mysql_real_escape_string() Quote Link to comment https://forums.phpfreaks.com/topic/160538-solved-select-between-dates/#findComment-847239 Share on other sites More sharing options...
timmah1 Posted June 1, 2009 Author Share Posted June 1, 2009 I apologize Maq, and thank you, that worked like I needed it to And roopurt18, you could have kept your comment to yourself, because in essence, you did tell me something :-) Quote Link to comment https://forums.phpfreaks.com/topic/160538-solved-select-between-dates/#findComment-847245 Share on other sites More sharing options...
Maq Posted June 1, 2009 Share Posted June 1, 2009 I apologize Maq, and thank you, that worked like I needed it to And roopurt18, you could have kept your comment to yourself, because in essence, you did tell me something :-) He's just helping you... Quote Link to comment https://forums.phpfreaks.com/topic/160538-solved-select-between-dates/#findComment-847249 Share on other sites More sharing options...
roopurt18 Posted June 1, 2009 Share Posted June 1, 2009 I apologize Maq, and thank you, that worked like I needed it to And roopurt18, you could have kept your comment to yourself, because in essence, you did tell me something :-) Hehe What I meant was I'm not helping you fix the problem you asked for help with until you fixed your other more serious problems. Quote Link to comment https://forums.phpfreaks.com/topic/160538-solved-select-between-dates/#findComment-847255 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.