Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

6. Integrating with Server-side Scripts > Time for action — creating a chart in...

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 .= "</chart>";....

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial