我试图将一些百分比存储到一个数组中,以便我可以稍后调用它来创建饼状图,但不知道如何做到这一点。这是我的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);
}
这应该可以满足您的要求,只是将变量替换为实际变量:
array_push($array, $value);
// This will add "$value" on to the end of $array, i.e the last element
也可以做得更简单:
$array[] = $value;
更新代码:
//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++;
}
$percentage_array = array();
for($index = 1; $index <= 10; $index++)
{
array_push($percentage_array, (($i[$index]/$total)*100));
#$degrees = (($percentage/100)*360);
}