1
我正在使用jQuery圖表模板 這些圖表中的值是由jQuery設置的,但我想從數據庫中獲取自己的值並將其設置爲這些值jQuery設置它的值。如你所知,在PHP中嵌入jQuery是不可能的,我該怎麼辦?如何使用PHP設置任何jQuery圖表數據
我正在使用jQuery圖表模板 這些圖表中的值是由jQuery設置的,但我想從數據庫中獲取自己的值並將其設置爲這些值jQuery設置它的值。如你所知,在PHP中嵌入jQuery是不可能的,我該怎麼辦?如何使用PHP設置任何jQuery圖表數據
它看起來像你使用morris.js庫。
我建議你回聲出JavaScript的一部分,是這樣的:
<?php
if($condition){
echo "<script>
Morris.Donut({
element: 'donut',
resize: true,
data: [";
foreach($value as $m){ //Your foreach here with $value you got from fetching data from a database via mysqli or PDO
$c = count($value);
$amount = $m['amount']; //just some example things
if($c != 1){
echo "{label: '".$type."', value: $amount"."},";
} else {
echo "{label: '".$type."', value: $amount"."}";
}
unset($value['0']);
}
echo" ]
});
</script>";
} else {
echo "<script>
Morris.Donut({
element: 'donut',
resize: true,
data: [{label: 'Nothing here yet', value: 1}]
});
</script>";
}
?>