【发布时间】:2014-11-05 14:15:25
【问题描述】:
我已经使用 mysql 和 php 从我的数据库中获取了 json 数据,现在想使用 $.ajax 函数将其传回并动态地创建一个样条图,任何帮助或示例将不胜感激。同样对于多次验血日期重复,我怎样才能只显示一个日期与多个验血结果。
这是我的php代码
header('Set Access-Control-Allow-Origin: *');
header('Content-type: application/json');
require_once"conn.php";
if($_SERVER['REQUEST_METHOD']=='GET'){
//recieve credentials from the user
$nhsno = mysqli_real_escape_string($conn, $_GET['pnhsno']);
//check the variables recieved are not empty
if($nhsno != ''){
$sql = "SELECT date,name,tname,value FROM examination e, testresults t, examtype ex, testname tn
WHERE e.patientnhs_no = '$nhsno' and e.etype_id = '1' and
e.examination_id = t.examination_id and e.etype_id = ex.etype_id and t.tname_id = tn.tname_id ";//create an sql statement
$result = $conn->query($sql);//run sqlm statement
$row = $result->fetch_assoc(); //fetch row of data
foreach ($result as $row){
$return[]=array('date'=>$row['date'],
'name'=>$row['name'],
'test name'=>$row['tname'],
'value'=>$row['value']);
}
}
}
$conn = null;
echo json_encode($return);
?>
这是我的 json 输出
[{"date":"2004-07-05","name":"blood test","test name":"t3","value":"6.8"}, {"date":"2004-07-05","name":"blood test","test name":"t4","value":"29"},{"date":"2004-07-05","name":"blood test","test name":"tsh","value":"0.01"},{"date":"2004-07-05","name":"blood test","test name":"thyroglobulin level","value":"0.5"},{"date":"2005-06-15","name":"blood test","test name":"t3","value":"5.2"},{"date":"2005-06-15","name":"blood test","test name":"t4","value":"30"},{"date":"2005-06-15","name":"blood test","test name":"tsh","value":"0.02"},{"date":"2005-06-15","name":"blood test","test name":"thyroglobulin level","value":"0.5"}]
【问题讨论】:
-
您使用哪个库来创建图表...
-
canvas jquery 图表
-
charts.js 或任何其他我能得到样条图的东西
-
您需要根据您要使用的 javascript 库来构建您的 json 响应...请参阅此示例:jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/…
-
非常感谢您的指导