简体   繁体   English

我将如何通过与另一个MySQL数组进行比较来更改它?

[英]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.

相关问题 我将如何改变整体 <li> 通过JavaScript - How Would i go about changing entire <li> via javascript 我将如何合并和转换数组中的 JS 对象 - How Would I Go About Merging & Transforming JS Objects In An Array 我将如何创建输入的二维数组 - How would I go about creating a 2-Dimensional Array of Input 我将如何处理? (Chrome扩展程序) - How would I go about this? (Chrome extension) 用户搜索后,如何更改div的内容? - How would I go about changing the contents of a div after the user searches? 当属性键动态变化时,我将如何 go 关于永久引用 Google 地理编码结果? - How would I go about permanently referencing Google geocoding results when the property keys are dynamically changing? 我将如何通过另一个方法对原始$(this)执行一个方法? - How would I go about performing a method through another method to the original $(this)? 我将如何将来自多个子组件的表单输入绑定到父组件中定义的数组? - How would I go about binding form input from multiple child components to an array defined in a parent component? AngularJS:如何基于ID从数组中选择一行 - AngularJS: How would I go about selecting a single row from an array based on ID 我 go 如何在不直接引用 object 的情况下获取数组内部的 object 的名称? - How would i go about getting the name of an object that's inside of an array without directly referencing the object?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM