Jump to content

select statement into an array


mishuk

Recommended Posts

Change of question.  I found a pie chart script (below) on this forum and am really struggling to substitute the $values = array(...); with an array taht is selected from the database I.e the values from the previous select statement.  Can anyone help?

 

$values = array(60, 40);

$im = imagecreate(350,190);
$bg = imagecolorallocate($im, 200, 200, 200);
$white = ImageColorAllocate ($im, 255, 255, 255);
$colors = array(
    imagecolorallocate($im, 0, 0, 0xFF),      //blue
    imagecolorallocate($im, 0xFF, 0, 0),     //red
    imagecolorallocate($im, 0, 0xFF, 0),     //green

);

$s_angle = 0;                          // pie slice start angle
$e_angle = 0;                          // pie slice end angle
$total = array_sum($values);
$k = count($values);
$cx = 175;
$cy = 90;                       // centre of the pie chart
for ($i=0; $i<$k; $i++)  {
    $a = $values[$i] / $total * 360;   // angle for this slice
    $e_angle += $a;
    imagefilledarc($im, $cx, $cy, 180, 180, $s_angle, $e_angle, $colors[$i], IMG_ARC_PIE);
    $s_angle += $a;                    // start angle for next slice
}
ImageString($im, 4, 30, 50, 'Male', $white);
ImageString($im, 4, 30, 70, 'Female', $white);
header ('content-type: image/png');
imagepng($im);
imagedestroy($im);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.