How I create a pie chart based on COUNT(php + mysql)?
<p>I have this database. I wanted to generate pie chart based from this database. The pie chart will generate based from the COUNT function. Can you help me to solve this?</p>

<p>Database Structure </p>

<p><a href="https://i.stack.imgur.com/ugb2y.png" rel="nofollow"><img src="https://i.stack.imgur.com/ugb2y.png" alt="enter image description here"></a></p>

<p>Here the code.The main page of my form.</p>

<pre><code>&lt;?php

mysql_connect("localhost","root","") or die("Error!");
mysql_select_db("try_pie_chart");

?&gt;


&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;PIE CHART&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;form name="count" action="piechart_post.php" method="post"&gt;


            &lt;select name="month"&gt;

 &lt;option value="01"&gt;January&lt;/option&gt;
 &lt;option value="02"&gt;February&lt;/option&gt;
 &lt;option value="03"&gt;March&lt;/option&gt;
 &lt;option value="04"&gt;April&lt;/option&gt;
 &lt;option value="05"&gt;May&lt;/option&gt;
 &lt;option value="06"&gt;June&lt;/option&gt;
 &lt;option value="07"&gt;July&lt;/option&gt;
 &lt;option value="08"&gt;August&lt;/option&gt;
 &lt;option value="09"&gt;September&lt;/option&gt;
 &lt;option value="10"&gt;October&lt;/option&gt;
 &lt;option value="11"&gt;November&lt;/option&gt;
 &lt;option value="12"&gt;December&lt;/option&gt;
 &lt;/select&gt;
 &lt;input type="text" name="year" /&gt;
 &lt;input type="submit" name="submit" value="Send" onclick = "&lt;?php $month=$_POST['month'] ?&gt;&lt;?php $year=$_POST['year'] ?&gt;"/&gt;

 &lt;/form&gt;


&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Here the code for form action. It will give output of COUNT</p>

<pre><code>&lt;?php

mysql_connect("localhost","root","") or die("Error");
mysql_select_db("try_pie_chart");

?&gt;



&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;PIE CHART&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;?php $month=$_POST['month'] ?&gt;&lt;?php $year=$_POST['year'] ?&gt;
&lt;?php
 $result = mysql_query("SELECT COUNT(*) AS total FROM table_details WHERE purpose='COURSES' AND (MONTH(date) LIKE '%$month' AND YEAR(date) LIKE '%$year%')") or die ("Error!");

 $result2 = mysql_query("SELECT COUNT(*) AS total FROM table_details WHERE purpose='BRIEFING' AND (MONTH(date) LIKE '%$month' AND YEAR(date) LIKE '%$year%')") or die ("Error!");

 $result3 = mysql_query("SELECT COUNT(*) AS total FROM table_details WHERE purpose='COMPETITION' AND (MONTH(date) LIKE '%$month' AND YEAR(date) LIKE '%$year%')") or die ("Error!");

 $result4 = mysql_query("SELECT COUNT(*) AS total FROM table_details WHERE purpose='INTERVIEW' AND (MONTH(date) LIKE '%$month' AND YEAR(date) LIKE '%$year%')") or die ("Error!");

$result5 = mysql_query("SELECT COUNT(*) AS total FROM table_details WHERE purpose='OTHERS' AND (MONTH(date) LIKE '%$month' AND YEAR(date) LIKE '%$year%')") or die ("Error!");

$result6 = mysql_query("SELECT COUNT(*) AS total FROM table_details WHERE (MONTH(date) LIKE '%$month' AND YEAR(date) LIKE '%$year%')") or die ("Error!");

?&gt;

 &lt;?php 
 $row=mysql_fetch_array($result);
 $row2=mysql_fetch_array($result2);
  $row3=mysql_fetch_array($result3);
 $row4=mysql_fetch_array($result4);
 $row5=mysql_fetch_array($result5);
 $row6=mysql_fetch_array($result6);

 ?&gt;

  &lt;table width="41%" border="1"&gt;
  &lt;tr&gt;
  &lt;td width="8%"&gt;BIL&lt;/td&gt;
  &lt;td width="42%"&gt;PURPOSE&lt;/td&gt;
  &lt;td width="50%"&gt;TOTAL&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;1&lt;/td&gt;
   &lt;td&gt;COURSES&lt;/td&gt;
  &lt;td&gt;&lt;?php echo $row['total'];  ?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;2&lt;/td&gt;
   &lt;td&gt;BRIEFING&lt;/td&gt;
   &lt;td&gt;&lt;?php echo $row2['total'];  ?&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
   &lt;td&gt;3&lt;/td&gt;
   &lt;td&gt;COMPETITION&lt;/td&gt;
   &lt;td&gt;&lt;?php echo $row3['total'];  ?&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;td&gt;4&lt;/td&gt;
    &lt;td&gt;INTERVIEW&lt;/td&gt;
    &lt;td&gt;&lt;?php echo $row4['total'];  ?&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;td&gt;5&lt;/td&gt;
    &lt;td&gt;OTHERS&lt;/td&gt;
     &lt;td&gt;&lt;?php echo $row5['total'];  ?&gt;&lt;/td&gt;
    &lt;/tr&gt;
     &lt;tr&gt;
    &lt;td colspan="2" align="right"&gt;Total Overall&lt;/td&gt;
    &lt;td&gt;&lt;strong&gt;&lt;?php echo $row6['total'];  ?&gt;&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;/table&gt;



     &lt;/body&gt;
     &lt;/html&gt;
</code></pre>