在我的 PHP 文件中,我正在运行以下 SQL 查询:
SELECT *
FROM national_age_gender_demographics INNER JOIN arizona_age_gender_demographics
WHERE national_age_gender_demographics.age_group = arizona_age_gender_demographics.age_group
ORDER BY national_age_gender_demographics.index_number";
现在,我正在尝试使用以下内容访问行以创建 JSON 数据:
for ($i = 0; $i < $numRows; $i++) {
if ($i != 0) {
$tableData .= ",[";
}
$tableData .= '"' . $row['national_age_gender_demographics.age_group'] . '",';
$tableData .= '"' . $row['national_age_gender_demographics.both_pop'] . '",';
$tableData .= '"' . $row['national_age_gender_demographics.male_pop'] . '",';
$tableData .= '"' . $row['national_age_gender_demographics.female_pop'] . '",';
$tableData .= '"' . $row['national_age_gender_demographics.male_percent'] . '",';
$tableData .= '"' . $row['national_age_gender_demographics.female_percent'] . '",';
$tableData .= '"' . $row['national_age_gender_demographics.both_percent'] . '",';
$tableData .= '"' . $row['national_age_gender_demographics.males_per_100_females'] . '",';
$tableData .= '"' . $row['arizona_age_gender_demographics.both_pop'] . '",';
$tableData .= '"' . $row['arizona_age_gender_demographics.male_pop'] . '",';
$tableData .= '"' . $row['arizona_age_gender_demographics.female_pop'] . '",';
$tableData .= '"' . $row['arizona_age_gender_demographics.male_percent'] . '",';
$tableData .= '"' . $row['arizona_age_gender_demographics.female_percent'] . '",';
$tableData .= '"' . $row['arizona_age_gender_demographics.both_percent'] . '",';
$tableData .= '"' . $row['arizona_age_gender_demographics.males_per_100_females'] . '"]';
if ($i != $numRows - 1) {
$row = mysqli_fetch_array($result);
}
}
在我的浏览器中输入 PHP 文件的 URL 时,我尝试访问连接表的每一行都得到未定义的索引。
我想知道,访问连接表的正确语法是什么?不,不要告诉我使用 json_encode,因为它会在 DataTables 中引发 JavaScript 错误。