gpt4 book ai didi

php - 如何使用 php 和 mysql 循环 data[] 系列

转载 作者:行者123 更新时间:2023-11-29 03:37:32 26 4
gpt4 key购买 nike

这是我的表结构。
enter image description here

enter image description here

我正在使用 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 子句(引用代码)中,显示了图形。看下面:enter image description hereSELECT jour_id, journal, citations, year 从 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 循环,但尽管它不起作用。请告诉我哪里出错了。请帮忙。

最佳答案

我建议您对数据库运行一个查询,准备包含三个系列的数组,然后在 PHP 中使用 json_encode() 并在 javascript 中通过 AJAX 获取数据。会更清晰。

关于php - 如何使用 php 和 mysql 循环 data[] 系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19219683/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com