[英]import data from localhost(phpmyadmin) to a web page“Highcharts”(as a project in phpmyadmin)
this is the code to display a columnrange(graphic in highcharts) in a web page with data from Phpmyadmin.The connection is estbalished but any thing is displayed when we make a request to our DB..Can you help me? 这是用Phpmyadmin中的数据在网页中显示列范围(高图中的图形)的代码。建立了连接,但是当我们向数据库请求时会显示任何内容。您能帮我吗? the code: 编码:
<!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>}
I think problem is here: 我认为问题出在这里:
// on crée la requête SQL $sql = 'SELECT question2 FROM questionnaire'; do { echo $data['question2']; } while ($data = mysql_fetch_assoc($sql));
you print something here. 你在这里打印东西。
and if we look on demos of highcharts it's look like: 如果我们看高图的演示,它看起来像:
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] }
but on your code it's look like you print something before you print [35.0,60.0];
但是在您的代码上,看起来就像您在打印[35.0,60.0];
之前先打印了一些[35.0,60.0];
And one more mistake(i think) you have data: [<?php
and you print again at [35.0,60.0];
还有一个错误(我认为),您有data: [<?php
,然后在[35.0,60.0];
再次打印[35.0,60.0];
i think your data looks like [[35.0, 60.0]]
. 我认为您的数据看起来像[[35.0, 60.0]]
。
And if you look in console (ctrl+shift+j on chrome) no error appears there? 而且,如果您查看控制台(Chrome上为ctrl + shift + j),那里没有出现错误?
CODE 码
<!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>}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.