我想通过json数据集(来自表“ score”)显示来自数据库的分数,该分数很好,但是我的quiz_id是外键,这意味着数据集将包含id,而不是测验的名称。在CanvasJS图表上看起来不太好。 quiz_name位于测验表中,主键为quiz_id。我将如何使json数据集包含quiz_name而不是quiz_id?
我的test.php,它正在创建json:
<?php
header('Content-Type: application/json');
$con = mysqli_connect("123.123.123.123", "Seba0702", "", "kayeetdb");
$data_points = array();
$result = mysqli_query($con, "SELECT * FROM score");
while($row = mysqli_fetch_array($result))
{
$point = array("label" => $row['quiz_id'] , "y" => $row['quiz_score']);
array_push($data_points, $point);
}
echo json_encode($data_points, JSON_NUMERIC_CHECK);
mysqli_close($con);
?>
我的桌子: 测验表:
得分表:
我希望json包含quiz_name和quiz_score。
答案 0 :(得分:0)
要从另一个表中检索信息,您需要一个联接
SELECT score.quiz_id, score.student_id, score.quiz_score, quiz.name
FROM score
INNER JOIN quiz on quiz.quiz_id = score.quiz_id