mishuk Posted March 14, 2007 Share Posted March 14, 2007 Hi. I am looking to place the results of this query into an array and was wondering how this is done? SELECT e.ethnicity, count(s.ethnic_id) FROM tbl_ethnicity e, tbl_student s WHERE e.ethnic_id = s.ethnic_id GROUP BY s.ethnic_id Thanks Link to comment https://forums.phpfreaks.com/topic/42657-select-statement-into-an-array/ Share on other sites More sharing options...
Barand Posted March 14, 2007 Share Posted March 14, 2007 try $ethnicity = array(); while (list ($eth, $tot) = mysql_fetch_row($result)) { $ethnicity[$eth] = $tot; } Link to comment https://forums.phpfreaks.com/topic/42657-select-statement-into-an-array/#findComment-206957 Share on other sites More sharing options...
mishuk Posted March 14, 2007 Author Share Posted March 14, 2007 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); Link to comment https://forums.phpfreaks.com/topic/42657-select-statement-into-an-array/#findComment-206978 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.