gpt4 book ai didi

php - 无法在 php 中显示来自 mysql 数据库的饼图值

转载 作者:行者123 更新时间:2023-11-29 23:02:02 25 4
gpt4 key购买 nike

我想绘制一个饼图,其中的值将从 MySQL 数据库中获取。但它不起作用。但如果我给出手动值,则会显示饼图。下面是我的代码:

<?php
include "libchart/classes/libchart.php";

header("Content-type: image/png");

$chart = new PieChart(500, 260);
$con=mysqli_connect("localhost","root","","bkash");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT count(*) FROM dialer_rate where mno='tnr' and success=1 ");
$result1 = mysqli_query($con,"SELECT count(*) FROM dialer_rate where mno='tnr' and failed=1");
$dataSet = new XYDataSet();
$dataSet->addPoint(new Point("Success", $result));
$dataSet->addPoint(new Point("Failed", $result1));
#$dataSet->addPoint(new Point(" (50)", 50));
$chart->setDataSet($dataSet);

$chart->setTitle("bKash USSD Dialer Success/Fail rate");
$chart->render();
?>

但是,如果我在以下两个字段中给出手动值,那么它就可以工作。请大家帮忙。

$dataSet->addPoint(new Point("Success", 20));
$dataSet->addPoint(new Point("Failed", 80));

最佳答案

试试这个

...
$result = mysqli_query($con,"SELECT count(*) as count FROM dialer_rate where mno='tnr' and success=1 ");
$result1 = mysqli_query($con,"SELECT count(*) as count1 FROM dialer_rate where mno='tnr' and failed=1");
$result = $result->fetch_object();
$result1 = $result1->fetch_object();
$dataSet = new XYDataSet();
$dataSet->addPoint(new Point("Success", $result->count));
$dataSet->addPoint(new Point("Failed", $result1->count1));
...

关于php - 无法在 php 中显示来自 mysql 数据库的饼图值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28446755/

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