PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/ cfstox/CFStox/FusionChartsFree/Code/PHP/UTF8Example/PieDataFrench.php

http://cfstox.googlecode.com/
PHP | 59 lines | 23 code | 9 blank | 27 comment | 1 complexity | 9386e62faa77bc9d883fb3779e103ec8 MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php
  2. echo pack("CCC",0xef,0xbb,0xbf);
  3. //We've included ../Includes/DBConn.php, which contains functions
  4. //to help us easily connect to a database.
  5. include("../Includes/DBConn.php");
  6. /*
  7. This page generates the XML data for the Pie Chart contained in JapaneseDBExample.php.
  8. For the sake of ease, we've used the same database as used by other examples.
  9. We have added one more table Japanese_Factory_Master with stores the names of the factory in Japanese language.
  10. Steps to ensure UTF8 xml output for FusionCharts:
  11. 1. Output the BOM bytes 0xef 0xbb 0xbf as shown above in the first few lines
  12. 2. Put the xml declaration <?xml version='1.0' encoding='UTF-8'?> immediately after the output from previous step.
  13. 3. Declare contentType to be text/xml, charSet.
  14. 4. Use getBytes to get the data from UTF field in the database and to convert it into String, use new String(bytes,"UTF-8")
  15. Do not output anything other than the BOM, xml declaration and the xml itself. (no empty lines too!)
  16. */
  17. //Connect to the DB
  18. $link = connectToDB();
  19. $useUTFQuery = "SET NAMES 'utf8'";
  20. $utfQueryResult = mysql_query($useUTFQuery);
  21. //$strXML will be used to store the entire XML document generated
  22. //Generate the graph element
  23. $strXML = "<graph caption='Industrie rapport de la production' subCaption='par quantité' decimalPrecision='0' showNames='1' numberSuffix=' Units' decimalPrecision='0' pieSliceDepth='30' >";
  24. // Fetch all factory records
  25. $strQuery = "select * from French_Factory_Master";
  26. $result = mysql_query($strQuery) or die(mysql_error());
  27. //Iterate through each factory
  28. if ($result) {
  29. while($ors = mysql_fetch_array($result)) {
  30. //Now create a second query to get details for this factory
  31. $strQuery = "select sum(Quantity) as TotOutput from Factory_Output where FactoryId=" . $ors['FactoryId'];
  32. $result2 = mysql_query($strQuery) or die(mysql_error());
  33. $ors2 = mysql_fetch_array($result2);
  34. //Generate <set name='..' value='..'/>
  35. $strXML .= "<set name='" . $ors['FactoryName'] . "' value='" . $ors2['TotOutput'] . "' />";
  36. //free the resultset
  37. mysql_free_result($result2);
  38. }
  39. }
  40. mysql_close($link);
  41. //Finally, close <graph> element
  42. $strXML .= "</graph>";
  43. //Set Proper output content-type and charset
  44. header('Content-type: text/xml;charset=UTF-8');
  45. //Just write out the XML data
  46. //NOTE THAT THIS PAGE DOESN'T CONTAIN ANY HTML TAG, WHATSOEVER
  47. ?>
  48. <?xml version='1.0' encoding='UTF-8'?><?php echo $strXML; ?>