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?
Database Structure
Here the code.The main page of my form.
<?php
mysql_connect("localhost","root","") or die("Error!");
mysql_select_db("try_pie_chart");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PIE CHART</title>
</head>
<body>
<form name="count" action="piechart_post.php" method="post">
<select name="month">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<input type="text" name="year" />
<input type="submit" name="submit" value="Send" onclick = "<?php $month=$_POST['month'] ?><?php $year=$_POST['year'] ?>"/>
</form>
</body>
</html>
Here the code for form action. It will give output of COUNT
<?php
mysql_connect("localhost","root","") or die("Error");
mysql_select_db("try_pie_chart");
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PIE CHART</title>
</head>
<body>
<?php $month=$_POST['month'] ?><?php $year=$_POST['year'] ?>
<?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!");
?>
<?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);
?>
<table width="41%" border="1">
<tr>
<td width="8%">BIL</td>
<td width="42%">PURPOSE</td>
<td width="50%">TOTAL</td>
</tr>
<tr>
<td>1</td>
<td>COURSES</td>
<td><?php echo $row['total']; ?></td>
</tr>
<tr>
<td>2</td>
<td>BRIEFING</td>
<td><?php echo $row2['total']; ?></td>
</tr>
<tr>
<td>3</td>
<td>COMPETITION</td>
<td><?php echo $row3['total']; ?></td>
</tr>
<tr>
<td>4</td>
<td>INTERVIEW</td>
<td><?php echo $row4['total']; ?></td>
</tr>
<tr>
<td>5</td>
<td>OTHERS</td>
<td><?php echo $row5['total']; ?></td>
</tr>
<tr>
<td colspan="2" align="right">Total Overall</td>
<td><strong><?php echo $row6['total']; ?></strong></td>
</tr>
</table>
</body>
</html>
