我正在尝试返回两个日期之间的表的一部分,但整个表一直返回。不仅仅是两个日期之间的值。你能告诉我我的代码在下面做错了吗?
$result = mysql_query("SELECT Name, DateTime, FROM names");
$sorting = mysql_query("WHERE DateTime between '2012-12-12 17:09:00' AND '2012-12-12 17:06:00'");
while($row = mysql_fetch_array($result,$sorting))
{
$output[] = $row;
}
print(json_encode($output));
mysql_close($con);
答案 0 :(得分:2)
BETWEEN 按照此顺序选择最小值和最大值...您将最大值和最小值传递给
答案 1 :(得分:2)
有几个语法错误,实际上你应该在将它发送到mysql_query()函数之前构建完整的查询:
$query = "SELECT Name, DateTime FROM names";
$query .= " WHERE DateTime BETWEEN '2012-12-12 17:06:00' AND '2012-12-12 17:09:00'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$output[] = $row;
}
print(json_encode($output));
mysql_close($con);
答案 2 :(得分:2)
您正在将2个mysql查询传递到您应该只给1的函数中。 排序变量被php丢弃,因为它仅用于返回一个正布尔值,用于表示数组的返回类型。
这里重写:
答案 3 :(得分:1)
$result = mysql_query("SELECT Name, DateTime, FROM names WHERE DateTime between '2012-12-12 17:09:00' AND '2012-12-12 17:06:00'");
while($row = mysql_fetch_array($result))
{
$output[] = $row;
}
print(json_encode($output));
mysql_close($con);