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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Kevin CrossChief 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CoyotesITCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.