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

Link to comment
Share on other sites

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
Share on other sites

$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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.