Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

how to calculate % in php from MySQL table?

Avatar of ftpphptest1
ftpphptest1 asked on
3 Comments1 Solution764 ViewsLast Modified:
i have 4 tables
i want to show the % of( each table number out of the sum of 4 tables)
how to do it in php?

i want to plot a chart to show the % of each table in each month
i.e. yaxis = %
   xaxis =  month

how to do it in php?
below is the fusionchart to show the data inside MySQL


//We've included ../Includes/FusionCharts.php and ../Includes/DBConn.php, which contains
//functions to help us easily embed the charts and connect to a database.
	FusionCharts Free - Database Example
	//You need to include the following JS file, if you intend to embed the chart using JavaScript.
	//Embedding using JavaScripts avoids the "Click to Activate..." issue in Internet Explorer
	//When you make your own charts, make sure that the path to this JS file is correct. Else, you would get JavaScript errors.
	<SCRIPT LANGUAGE="Javascript" SRC="MyFCPHPClassCharts/FusionCharts/FusionCharts.js"></SCRIPT>
	<style type="text/css">
	body {
		font-family: Arial, Helvetica, sans-serif;
		font-size: 12px;
		font-family: Arial, Helvetica, sans-serif;
		font-size: 12px;
<h2><a href="http://www.fusioncharts.com" target="_blank">FusionCharts Free</a> -Database and Drill-Down Example</h2>
	//In this example, we show how to connect FusionCharts to a database.
	//For the sake of ease, we've used an MySQL databases containing two
	// Connect to the DB
	$link = connectToDB();
	//$strXML will be used to store the entire XML document generated
	//Generate the graph element
	$strXML = "<graph caption='Factory Output report' subCaption='By Quantity' pieSliceDepth='30' showBorder='1' showNames='1' formatNumberScale='0' numberSuffix=' Units' decimalPrecision='0'>";
	// Fetch all factory records
	$strQuery = "select * from Factory_Master";
	$result = mysql_query($strQuery) or die(mysql_error());
	/*Iterate through each factory
	if ($result) {
		while($ors = mysql_fetch_array($result)) {
			//Now create a second query to get details for this factory
			$strQuery = "select sum(Quantity) as TotOutput from Factory_Output where FactoryId=" . $ors['FactoryId'];
			$result2 = mysql_query($strQuery) or die(mysql_error()); 
			$ors2 = mysql_fetch_array($result2);
			//Generate <set name='..' value='..' />        
			$strXML .= "<set name='" . $ors['FactoryName'] . "' value='" . $ors2['TotOutput'] . "' />";
			//free the resultset
	//Finally, close <graph> element
	$strXML .= "</graph>";
	//Create the chart - Pie 3D Chart with data from $strXML
	echo renderChart("MyFCPHPClassCharts/FusionCharts/FCF_Pie3D.swf", "", $strXML, "FactorySum", 650, 450);
<a href='../NoChart.html' target="_blank">Unable to see the chart above?</a>
<H5 ><a href='../default.htm'>&laquo; Back to list of examples</a></h5>
Avatar of agamal
agamalFlag of United Arab Emirates image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answers