Reputation: 217
I'm wondering why this where clause isn't working in MySql? I have the column of runDate set to the data type "date" and the date appears in the format below:
<?php
$con = mysql_connect("***","***","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("ArnoldsPizzaShop", $con);
$result = mysql_query("SELECT * FROM runinfo WHERE runDate = 2013-01-06");
while($row = mysql_fetch_array($result))
{
echo $row['route'] ;
}
mysql_close($con);
?>
Upvotes: 2
Views: 6255
Reputation: 247620
You need single quotes around the date value:
SELECT *
FROM runinfo
WHERE runDate = '2013-01-06'
So your code would be:
mysql_query("SELECT * FROM runinfo WHERE runDate = '2013-01-06'");
If your runDate
column also contains the time, then you might want to use:
SELECT *
FROM runinfo
WHERE Date(runDate) = '2013-01-06'
Or even:
SELECT *
FROM runinfo
WHERE runDate between '2013-01-06' and '2013-01-07'
Upvotes: 7