2

我想知道为什么这个 where 子句在 MySql 中不起作用?我将 runDate 列设置为数据类型“日期”,日期以以下格式显示:

<?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);
?>
4

1 回答 1

7

您需要在日期值周围加上单引号:

SELECT * 
FROM runinfo 
WHERE runDate = '2013-01-06'

所以你的代码是:

mysql_query("SELECT * FROM runinfo WHERE runDate = '2013-01-06'");

如果您的runDate列还包含时间,那么您可能需要使用:

SELECT * 
FROM runinfo 
WHERE Date(runDate) = '2013-01-06'

甚至:

SELECT * 
FROM runinfo 
WHERE runDate between '2013-01-06' and '2013-01-07'
于 2013-01-08T21:12:59.067 回答