home *** CD-ROM | disk | FTP | other *** search
- /* ---------------------------------------------------------------- */
- /* 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 constructs the html page dynamically */
- /* inserting the values from the result set into the parameters of */
- /* the Pie Chart 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";
- $result1 = mysql_query($query) or die("Query failed : " . mysql_error());
-
- /* Performing SQL query for Product Y*/
- $query = "Select Value from SalesBar where Year=2004 and Product='Y' ORDER BY Month";
- $result2 = mysql_query($query) or die("Query failed : " . mysql_error());
-
-
-
- /* Construct HTML page containing Pie Chart Applet*/
- print "<html>\n";
- print "<head>\n";
- print "<title>3D Pie Chart</title>\n";
- print "</head>\n";
- print "<body>\n";
- print "<applet code='PiechartApplet.class' archive='Piechart.jar' width='500' height='420'>\n";
- print " <!-- Start Up Parameters -->\n";
- print " <PARAM name='LOADINGMESSAGE' value='Pie Chart Loading - Please Wait.'> <!-- Message to be displayed on Startup -->\n";
- print " <PARAM name='STEXTCOLOR' value='0,0,100'> <!-- Message Text Color-->\n";
- print " <PARAM name='STARTUPCOLOR' value='255,255,255'> <!-- Applet Background color -->\n";
- print " \n";
- print " <!-- Property file -->\n";
- print " <PARAM name='chartproperties' value='piepropsdb.txt'>\n";
- print " \n";
- print " <!-- Chart Data --> \n";
-
- $data_num = 1;
- while ($line = mysql_fetch_array($result1, MYSQL_ASSOC)) {
-
- foreach ($line as $col_value) {
- print "<param name='data".$data_num."series1' value='".$col_value."'>\n";
- }
- $data_num = $data_num +1;
-
- }
-
-
- $data_num = 1;
- while ($line = mysql_fetch_array($result2, MYSQL_ASSOC)) {
-
- foreach ($line as $col_value) {
- print "<param name='data".$data_num."series2' value='".$col_value."'>\n";
- }
- $data_num = $data_num +1;
-
- }
-
- print " \n";
- print "</applet>\n";
- print " \n";
- print "</body>\n";
- print "</html>\n";
-
-
- /* Free resultset */
- mysql_free_result($result1);
- mysql_free_result($result2);
-
- /* Closing connection */
- mysql_close($link);
-
-
- ?>
-
-
-
-
-