PHP mySQL Select query by date

I'm trying to use the following code to select data by a date range and display it.  I can display it fine, but I can't seem to get the mySQL query right...

$url[3]; is an exploded query_string.  The value is 11/01/08

$searchval = $url[3];
        $itemsbydate = mysql_query("SELECT id,group_number,group_name,date_received,disposition,DATE_FORMAT(date_received,'%Y%m%d') as recdate from inquiries where userid='$userid' and recdate=$searchval");
        while($disprow = mysql_fetch_array($itemsbydate, MYSQL_ASSOC))
      {
LVL 11
SeanStricklandAsked:
Who is Participating?
 
Kevin CrossConnect With a Mentor Chief Technology OfficerCommented:
Here is corrected query.  

+Think you want to use date_received in the where clause as recdate is your column alias.
+Use date() to remove any timestamps so everything on 11/01/08 will match regardless of time.
+You may need to have single quotes around date as well.
$itemsbydate = mysql_query("SELECT id,group_number,group_name,date_received,disposition,DATE_FORMAT(date_received,'%Y%m%d') as recdate from inquiries where userid='$userid' and date(date_received) = $searchval");
 
<!-- OR -->
 
$itemsbydate = mysql_query("SELECT id,group_number,group_name,date_received,disposition,DATE_FORMAT(date_received,'%Y%m%d') as recdate from inquiries where userid='$userid' and date(date_received) = '$searchval'");

Open in new window

0
 
Kevin CrossChief Technology OfficerCommented:
Try like this:
$itemsbydate = mysql_query("SELECT id,group_number,group_name,date_received,disposition,DATE_FORMAT(date_received,'%Y%m%d') as recdate from inquiries where userid='$userid' and date(recdate) = $searchval");

Open in new window

0
 
CoyotesITConnect With a Mentor Commented:
Try making your $searchval look like "2008-11-01"

and see if you can return the values you are looking for.
0
 
SeanStricklandAuthor Commented:
Thanks!  Both of your solutions combined helped me.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.