这是我的表结构。


我正在使用highcharts
下面是我的代码:
$(function () {
$('#container_journal').highcharts({
xAxis: {
categories: [
'1995', '1996', '1997', '1988'
]
},
yAxis: {
title: {
text: 'Citations'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: ''
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: [{
name: 'A + U-Architecture and Urbanism',
data: [<?php
$test_q = mysql_query("SELECT jour_id, journal, citations, year FROM journ_graph WHERE jour_id = '1'");
while($row_q = mysql_fetch_array($test_q)){
$year_q = $row_q['year'];
$citations_q = $row_q['citations'];
echo $citations_q.',';
}
?>]
},{
name: 'AACE International. Transactions of the Annual Meeting',
data: [
<?php
$test_q = mysql_query("SELECT jour_id, journal, citations, year FROM journ_graph WHERE jour_id = '2'");
while($row_q = mysql_fetch_array($test_q)){
$year_q = $row_q['year'];
$citations_q = $row_q['citations'];
echo $citations_q.',';
}
?>]
},{
name: 'AACL Bioflux',
data: [
<?php
$test_q = mysql_query("SELECT jour_id, journal, citations, year FROM journ_graph WHERE jour_id = '3'");
while($row_q = mysql_fetch_array($test_q)){
$year_q = $row_q['year'];
$citations_q = $row_q['citations'];
echo $citations_q.',';
}
?>]
}
?>]
]
});
});在这里,我手动输入id。在where子句(参见代码)中,显示了图形。如下所示:

在上面的语句中选择jour_id,journal,citations,year FROM journ_graph WHERE jour_id = '3‘在上面的语句中,我手动输入id,但我需要它来自第一个表jour_id。
我也试过了,但不起作用。
series: [
<?php
$query_jour = mysql_query("SELECT jour_id, journal, citations, year FROM journ_graph");
$query_journ_count = mysql_num_rows($query_jour);
while($row_journ = mysql_fetch_array($query_jour)){
$jour_id = $row_journ['jour_id'];
?>
{
data: [<?php
$test_q = mysql_query("SELECT jour_id, journal, citations, year FROM journ_graph WHERE jour_id = '$jour_id'");
while($row_q = mysql_fetch_array($test_q)){
$year_q = $row_q['year'];
$citations_q = $row_q['citations'];
echo $citations_q.',';
}
?>]
}
<?php
}?>我使用了两个while循环,但即使它不工作。请告诉我哪里出错了。请帮帮忙。
发布于 2013-10-07 17:55:22
我建议您对数据库运行一次查询,准备包含三个序列的数组,然后在PHP中使用json_encode(),在javascript中通过AJAX获取数据。它会变得更加清晰。
https://stackoverflow.com/questions/19219683
复制相似问题