jamesflowers Report post Posted September 22, 2012 (edited) I am trying to implement FusionCharts using the example given in the downloads FusionCharts/Code/PHPClass/DB_dataURL/Default.php I have changed the PHP to my own DB as a select statement.. "select country, count(customerNumber) count from customers group by country"; and the $FC->addDataFromDatabase($result, "country", "count"); (will include all code below) But the page returns , the box shows but no data is returned . please advise Thanks James --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- <?php //We've included ../Includes/FusionCharts_Gen.php, which contains //FusionCharts PHP Class to help us easily embed charts //We've also used ../Includes/DBConn.php to easily connect to a database. include("../Includes/FusionCharts_Gen.php"); include("../Includes/DBConn.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <TITLE> FusionCharts XT - Database Example </TITLE> <?php //You need to include the following JS file, if you intend to embed the chart using JavaScript. //Embedding using JavaScripts avoids the "Click to Activate..." issue in Internet Explorer //When you make your own charts, make sure that the path to this JS file is correct. Else, you would get JavaScript errors. ?> <script LANGUAGE="Javascript" SRC="../../FusionCharts/FusionCharts.js"></SCRIPT> <!--[if IE 6]> <script type="text/javascript" src="../assets/ui/js/DD_belatedPNG_0.0.8a-min.js"></script> <script> /* select the element name, css selector, background etc */ DD_belatedPNG.fix('img'); /* string argument can be any CSS selector */ </script> <![endif]--> <link href="../assets/ui/css/style.css" rel="stylesheet" type="text/css" /> <style type="text/css"> h2.headline { font: normal 110%/137.5% "Trebuchet MS", Arial, Helvetica, sans-serif; padding: 0; margin: 25px 0 25px 0; color: #7d7c8b; text-align: center; } p.small { font: normal 68.75%/150% Verdana, Geneva, sans-serif; color: #919191; padding: 0; margin: 0 auto; width: 664px; text-align: center; } </style> </head> <BODY> <div class="content-area"> <div id="content-area-inner-main"> <div class="gen-chart-render"> <CENTER> <?php //In this example, we show how to connect FusionCharts to a database. //For the sake of ease, we've used an MySQL databases containing two //tables. // Connect to the Database $link = connectToDB(); # Create pie 3d chart object using FusionCharts PHP Class $FC = new FusionCharts("Pie3D","650","450"); # Set Relative Path of swf file. $FC->setSWFPath("../../FusionCharts/"); # Define chart attributes $strParam="caption=Customer Count Per City;subCaption=By Quantity;pieSliceDepth=30; showBorder=0;numberSuffix= Units"; # Set chart attributes $FC->setChartParams($strParam); // Fetch all factory records usins SQL Query //Store chart data values in 'total' column/field and category names in 'FactoryName' $strQuery = "select country, count(customerNumber) count from customers group by country"; $result = mysql_query($strQuery) or die(mysql_error()); //Pass the SQL Query result to the FusionCharts PHP Class function //along with field/column names that are storing chart values and corresponding category names //to set chart data from database if ($result) { $FC->addDataFromDatabase($result, "country", "count"); } mysql_close($link); # Render the chart $FC->renderChart(); ?> </CENTER> </div> <div class="clear"></div> <p> </p> <p class="small"> </p> <div class="underline-dull"></div> </div> </div> <div id="footer"> <ul> <li><a href="../index.html"><span>« Back to list of examples</span></a></li> <li class="pipe">|</li> <li><a href="../NoChart.html"><span>Unable to see the chart above?</span></a></li> </ul> </div> </div> </BODY> </HTML> Edited September 22, 2012 by jamesflowers Share this post Link to post Share on other sites
Guest Sashibhusan Report post Posted September 24, 2012 Hi, With regard to your query, please note that the correct syntax for "addDataFromDatabase()" method is as shown below: Syntax: addDataFromDatabase(resource $query_result, string $db_field_ChartData[, string $db_field_CategoryNames, string $strParam, string $link]) Where, the second argument is the "Database field that contains data values" and third argument is "database field that contains category names". So, could you please try by passing the parameters to the PHP function "addDataFromDatabase()" as below? Ref. Code: $FC->addDataFromDatabase($result, "count", "country"); Also, could you please confirm once that the SQL statement is executed and returning the required values from the database properly? Awaiting your response! Share this post Link to post Share on other sites
jamesflowers Report post Posted September 24, 2012 Hi, With regard to your query, please note that the correct syntax for "addDataFromDatabase()" method is as shown below: Syntax: addDataFromDatabase(resource $query_result, string $db_field_ChartData[, string $db_field_CategoryNames, string $strParam, string $link]) Where, the second argument is the "Database field that contains data values" and third argument is "database field that contains category names". So, could you please try by passing the parameters to the PHP function "addDataFromDatabase()" as below? Ref. Code: $FC->addDataFromDatabase($result, "count", "country"); Also, could you please confirm once that the SQL statement is executed and returning the required values from the database properly? Awaiting your response! Many thanks , I had the ($result, "count", "country"); around the wrong way.....it works fantasrtically now... Share this post Link to post Share on other sites
Guest Sashibhusan Report post Posted September 25, 2012 Hi, I am glad to hear that the solution provided to you, has resolved your issue. Please do let us know if we could be of any further help! Share this post Link to post Share on other sites