gpt4 book ai didi

mysql - 将数据从本地主机(phpmyadmin)导入到网页“Highcharts”(作为 phpmyadmin 中的项目)

转载 作者:行者123 更新时间:2023-11-29 22:10:31 24 4
gpt4 key购买 nike

这是在网页中显示列范围( Highcharts 中的图形)的代码,其中包含来自 Phpmyadmin 的数据。连接已建立,但当我们向数据库发出请求时,会显示任何内容。您能帮助我吗?代码:

<!DOCTYPE HTML>
<?php

$db = mysqli_connect('localhost', 'root') or die("Error " . mysqli_error($db));
mysqli_set_charset($db,"utf8");

// on sélectionne la base
$db_selected=mysqli_select_db($db,'outil_échantillonnage_et_analyse_de_données') or die("Error in the consult.." . mysqli_error($db));
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Example</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<style type="text/css">
${demo.css}
</style>
<script type="text/javascript">
$(function () {

$('#container').highcharts({

chart: {
type: 'columnrange',
inverted: true
},

title: {
text: 'Moyenne age'
},

subtitle: {
text: 'informations sur la moyenne d age des participants'
},

xAxis: {
categories: []
},

yAxis: {
title: {
text: 'Age ( ans )'
}
},

tooltip: {
valueSuffix: 'ans'
},

plotOptions: {
columnrange: {
dataLabels: {
enabled: true,
formatter: function () {
return this.y + 'ans';
}
}
}
},

legend: {
enabled: false
},

series: [{
name: 'moyenne age',
data: [<?php

// on crée la requête SQL
$sql = 'SELECT question2 FROM questionnaire';
do { echo $data['question2']; } while ($data = mysql_fetch_assoc($sql));

// on envoie la requête
$req = mysqli_query($db, $sql) ;

do { ?><?php switch ($data['question2']) {
case 'moins de 18ans':?>
[0.0,18.0],
<?php break;
case '18-35 ans':?>
[18.0,35.0],
<?php break;
case '35-60 ans':?>
[35.0,60.0];
<?php break;
case 'plus de 60ans':?>
[60.0,100.0];
<?php break;
}; ?>,<?php } while ($data = mysqli_fetch_assoc($req);

?>,

]
}]

});

});
<?php
mysqli_close($db);
?>

</script>
</head>
<body>
<script src="../../js/highcharts.js"></script>
<script src="../../js/highcharts-more.js"></script>
<script src="../../js/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>


</body>
</html>}

最佳答案

我认为问题出在这里:
// on crée la requête SQL
$sql = 'SELECT question2 FROM questionnaire';
do { echo $data['question2']; } while ($data = mysql_fetch_assoc($sql));
你在这里打印一些东西。
如果我们看一下 highcharts 的演示,它看起来像:
series: [{
name: 'Tokyo',
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
}

但在你的代码中,看起来你在打印 [35.0,60.0]; 之前打印了一些东西
(我认为)你还有一个错误 data: [<?php然后您再次打印 [35.0,60.0];我认为你的数据看起来像 [[35.0, 60.0]] .
如果你查看控制台(chrome 上的 ctrl+shift+j),那里不会出现错误?

代码

    <!DOCTYPE HTML>
<?php

$db = mysqli_connect('localhost', 'root') or die("Error " . mysqli_error($db));
mysqli_set_charset($db,"utf8");

// on sélectionne la base
$db_selected=mysqli_select_db($db,'outil_échantillonnage_et_analyse_de_données') or die("Error in the consult.." . mysqli_error($db));
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Example</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<style type="text/css">
${demo.css}
</style>
<script type="text/javascript">
$(function () {

$('#container').highcharts({

chart: {
type: 'columnrange',
inverted: true
},

title: {
text: 'Moyenne age'
},

subtitle: {
text: 'informations sur la moyenne d age des participants'
},

xAxis: {
categories: []
},

yAxis: {
title: {
text: 'Age ( ans )'
}
},

tooltip: {
valueSuffix: 'ans'
},

plotOptions: {
columnrange: {
dataLabels: {
enabled: true,
formatter: function () {
return this.y + 'ans';
}
}
}
},

legend: {
enabled: false
},

series: [{
name: 'moyenne age',
data: [<?php

// on crée la requête SQL
$sql = 'SELECT question2 FROM questionnaire';

// on envoie la requête
$req = mysqli_query($db, $sql) ;

do { ?><?php switch ($data['question2']) {
case 'moins de 18ans':?>
[0.0,18.0],
<?php break;
case '18-35 ans':?>
[18.0,35.0],
<?php break;
case '35-60 ans':?>
[35.0,60.0];
<?php break;
case 'plus de 60ans':?>
[60.0,100.0];
<?php break;
}; ?>,<?php } while ($data = mysqli_fetch_assoc($req);

?>,
]
}]

});

});
<?php
mysqli_close($db);
?>

</script>
</head>
<body>
<script src="../../js/highcharts.js"></script>
<script src="../../js/highcharts-more.js"></script>
<script src="../../js/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>


</body>
</html>}

关于mysql - 将数据从本地主机(phpmyadmin)导入到网页“Highcharts”(作为 phpmyadmin 中的项目),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31722727/

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