Time for action — creating a chart in PHP using data from MySQL
1. Create a blank PHP file named
chart_from_mysql.php
in the root of your web application.2. Type the following code in it:
<?php include("/Includes/FusionCharts.php"); include("/Includes/DBConn.php"); ?> <html> <head> <title>FusionCharts XT - Plotting data from MySQL</title> <script src="Charts/FusionCharts.js"></script> </head> <body> <center> <?php // Connect to the Database $link = connectToDB(); // Fetch all total revenue of the last 3 years using SQL Query $strQuery = "SELECT SUM( order_amount ) AS SUM, YEAR( order_date ) AS YEAR FROM orders GROUP BY YEAR ( order_date )"; $result = mysql_query($strQuery) or die(mysql_error()); $strXML = "<chart caption='Annual Revenue - last 3 years' numberPrefix='$'>"; while($row = mysql_fetch_array($result, MYSQL_BOTH)) { $strXML .= "<set label = '".$row['YEAR']."' value = '".$row['SUM']."' />"; } $strXML .=...