我设法在sql中执行一个简单的连接语句来查询我想要的表,但是我在json中输入有问题。我一直得到输出[]给我看起来像一个空数组。
$date_1 = mysql_real_escape_string($_GET["date_1"]);
$date_2 = mysql_real_escape_string($_GET["date_2"]);
$sport_type = ucfirst("$sport_type");
$sport_type = "Cycling - ".$sport_type;
$date1=explode('/',$date_1);
$d = $date1[0];
$m = $date1[1];
$y = $date1[2];
$date1_string = $y.'-'.$m.'-'.$d;
$date2=explode('/',$date_2);
$d = $date2[0];
$m = $date2[1];
$y = $date2[2];
$date2_string = $y.'-'.$m.'-'.$d;
// sql query to display info from database
$sql = "SELECT name, Cyclist.ISO_id, country_name, gdp, population From Cyclist INNER JOIN Country ON Cyclist.ISO_id=Country.ISO_id WHERE dob BETWEEN $date1_string AND $date2_string ";
$res =& $db->query($sql);
$list = json_encode($res->fetchAll());
if (PEAR::isError($res)) {
die($res->getMessage());
}
?>
<?php
echo $list
?>
我哪里错了?
答案 0 :(得分:0)
MySQL日期字段的格式为YYYY-MM-DD而非DD-MM-YYY,因为您正在尝试。