我设法在 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
?>
我哪里错了?