rubing Posted March 17, 2008 Share Posted March 17, 2008 I am trying to retrieve a set of results from a mysql within a specified date range. My original query without specifying the date range worked fine! However when I introduced the BETWEEN statement (incl. $POST arrays) it stopped working. Now, I get no results!! Anybody have a clue?? $query_str = "SELECT DISTINCT MusicEvents.Band,BandSite FROM MusicEvents LEFT JOIN Bands ON MusicEvents.Band=Bands.Band WHERE BandSite IS NULL BETWEEN '". $_POST['startdate'] ."' AND '". $_POST['enddate']. "' ORDER BY Date ASC, MusicEvents.Band ASC"; Link to comment https://forums.phpfreaks.com/topic/96487-date-range-from-_post-array-does-not-work-in-mysql-query/ Share on other sites More sharing options...
nibbo Posted March 17, 2008 Share Posted March 17, 2008 I think you need another AND in there... WHERE BandSite IS NULL AND whateverdate BETWEEN ... Link to comment https://forums.phpfreaks.com/topic/96487-date-range-from-_post-array-does-not-work-in-mysql-query/#findComment-493793 Share on other sites More sharing options...
rubing Posted March 17, 2008 Author Share Posted March 17, 2008 I'm afraid that didn't make a difference Link to comment https://forums.phpfreaks.com/topic/96487-date-range-from-_post-array-does-not-work-in-mysql-query/#findComment-493800 Share on other sites More sharing options...
rubing Posted March 17, 2008 Author Share Posted March 17, 2008 I just tried adding in the command manually and it didn't work...hmmmm Link to comment https://forums.phpfreaks.com/topic/96487-date-range-from-_post-array-does-not-work-in-mysql-query/#findComment-493803 Share on other sites More sharing options...
teng84 Posted March 17, 2008 Share Posted March 17, 2008 what is the error message? Link to comment https://forums.phpfreaks.com/topic/96487-date-range-from-_post-array-does-not-work-in-mysql-query/#findComment-493804 Share on other sites More sharing options...
rubing Posted March 17, 2008 Author Share Posted March 17, 2008 AHHHH YES, I forgot...I had error messages suppressed. Let's see, the error message is: Fatal error: Call to a member function fetch_assoc() on a non-object in /home/rubing/public_html/exec/yahoo.php on line 47 Link to comment https://forums.phpfreaks.com/topic/96487-date-range-from-_post-array-does-not-work-in-mysql-query/#findComment-493809 Share on other sites More sharing options...
rubing Posted March 17, 2008 Author Share Posted March 17, 2008 $query_str = "SELECT DISTINCT MusicEvents.Band,BandSite FROM MusicEvents LEFT JOIN Bands ON MusicEvents.Band=Bands.Band WHERE BandSite IS NULL AND BETWEEN '". $_POST['startdate'] ."' AND '". $_POST['enddate']. "' ORDER BY Date ASC, MusicEvents.Band ASC"; $result = $conn->query($query_str); while(($row = $result->fetch_assoc()) !==NULL ) //This is LINE 47 { Link to comment https://forums.phpfreaks.com/topic/96487-date-range-from-_post-array-does-not-work-in-mysql-query/#findComment-493816 Share on other sites More sharing options...
rubing Posted March 17, 2008 Author Share Posted March 17, 2008 I think I just forgot to put in the date column... YES BROTHERS... WE solved it. First of all, i stupidly omitted the date collum before the BETWEEN COMMAND Secondly, there needed to be another AND statement as follows: $query_str = "SELECT DISTINCT MusicEvents.Band,BandSite FROM MusicEvents LEFT JOIN Bands ON MusicEvents.Band=Bands.Band WHERE BandSite IS NULL AND Date BETWEEN '". $_POST['startdate'] ."' AND '". $_POST['enddate']. "' ORDER BY Date ASC, MusicEvents.Band ASC"; Link to comment https://forums.phpfreaks.com/topic/96487-date-range-from-_post-array-does-not-work-in-mysql-query/#findComment-493821 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.