Jump to content

Date Range from $_POST array does not work in mysql query


rubing

Recommended Posts

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";

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

$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

{	

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";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.