0
我有困难的时间排除故障,为什么我似乎无法像在index.php上运行这个WordPress内部。它独立运作。我在wordpress db中创建了额外的表。我运行时看到空白数据。不知何故,它没有收集数据。我在研究后才知道我需要使用$ wpdb和get_results。所以,将它从这个老代码:WordPress的SQL fetch_assoc
$result = $db->query("SELECT name,rating FROM wp_figure where status = '1' ORDER BY rating DESC");
/使用WordPress代码/
<?php
global $wpdb;
$results = $wpdb->get_results("SELECT name,rating FROM wp_figure where status = '1' ORDER BY rating DESC");
?>
//上的header.php
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['name', 'Rating'],
<?php
if($result->num_rows > 0){
while($row = $result->fetch_assoc()){
echo "['".$row['name']."', ".$row['rating']."],";
}
}
?>
]);
var options = {
title: 'Figure',
width: 900,
height: 500,
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
on the body html i have
<body>
<!-- Display the pie chart -->
<div id="piechart"></div>
</body>
谢谢艾哈迈德...在下面显示的下一个PHP进入空白。我如何将它转换为兼容的wordpress。 ''code'<?php if($ result-> num_rows> 0){0} {0} {0} {0} {'$'='result' ,“。$ row ['rating']。”],“; } } ?> – pnsguardian