/* ---------------------------------------------------------------- */
/* The following script is a sample script designed to demonstrate  */
/* a method for creating real-time dynamic pie charts from data     */
/* held within databases.                                           */
/*                                                                  */
/* This sample connects to a MySQL database and reads data from     */
/* a table "SalesBar". It then formats the data for use by the      */
/* Bar Graph Applet.                                                */
/*                                                                  */
/* You may freely copy and modify this script to suite your own     */
/* requirements.                                                    */
/*                                                                  */
/* ---------------------------------------------------------------- */

<?php
    /* Connect to the MySQL Database Server */
    $link = mysql_connect("localhost", "[DB_USERNAME]", "[DB_PASSWORD]")
        or die("Could not connect : " . mysql_error());
    
    /* Select Database testDB2 */
    mysql_select_db('[DB_NAME]',$link) or die("Could not select database");

    /* Performing SQL query for Product X*/
    $query = "Select Value from SalesBar where Year=2004 and Product='X' ORDER BY Month";
    $result = mysql_query($query) or die("Query failed : " . mysql_error());

    /* Construct the return data for Product X */
    print "<!-- Data for Product X -->\n";
    
    $data_num = 1;
    while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    
        foreach ($line as $col_value) {
           print "data".$data_num."series1: ".$col_value."\n";
        }
        $data_num = $data_num +1;
    
    }
        

    /* Performing SQL query for Product Y*/
    $query = "Select Value from SalesBar where Year=2004 and Product='Y' ORDER BY Month";
    $result = mysql_query($query) or die("Query failed : " . mysql_error());

    /* Construct the return data for Product Y */
    print "<!-- Data for Product Y -->\n";
    
    $data_num = 1;
    while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    
        foreach ($line as $col_value) {
           print "data".$data_num."series2: ".$col_value."\n";
        }
        $data_num = $data_num +1;
    
    }
    


    /* Free resultset */
    mysql_free_result($result);

    /* Closing connection */
    mysql_close($link);


?>


 

