[英]How would i go about changing a MySQL array by comparing it to another?
I want to display a score coming from my database through a json dataset (from the table "score"), which works fine, but my quiz_id is the foreign key, which means the dataset will contain the id, and not the name of the quiz. 我想显示一个通过json数据集(来自表“ score”)来自数据库的分数,它可以正常工作,但是我的quiz_id是外键,这意味着数据集将包含ID,而不是名称。测验。 Which doesn't look good on the CanvasJS graph. 在CanvasJS图表上看起来不太好。 The quiz_name is located in the quiz table, with the primary key quiz_id. quiz_name位于测验表中,主键为quiz_id。 How would i make the json dataset include the quiz_name instead of quiz_id? 我将如何使json数据集包含quiz_name而不是quiz_id?
my test.php, which is creating the json: 我的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);
?>
My tables: Quiz Table: 我的表格:测验表:
Score Table: 得分表:
I want the json to include the quiz_name and quiz_score. 我希望json包含quiz_name和quiz_score。
For retrieve infor from another table you need a join 要从另一个表中检索信息,您需要一个联接
SELECT score.quiz_id, score.student_id, score.quiz_score, quiz.name
FROM score
INNER JOIN quiz on quiz.quiz_id = score.quiz_id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.