我正在尝试将我计算出的一些百分比存储到一个数组中,以便我以后可以调用它来创建一个饼图,但不知道如何去做。到目前为止,这是我计算百分比的 PHP 代码:提前感谢您的帮助!
//execute the SQL query and return records
$result = mysql_query("SELECT book_id, COUNT(*) FROM loan GROUP BY book_id ASC ORDER BY count(*) DESC LIMIT 10");
$book_count = mysql_num_rows($result);
$step = 1;
while($row = mysql_fetch_array($result))
{
$total = $total + $row['COUNT(*)'];
$i[$step] = $row['COUNT(*)'];
$step++;
}
for($index = 1; $index <= 10; $index++)
{
$percentage[$index] = (($i[$index]/$total)*100);
#$degrees = (($percentage/100)*360);
}