billsinc Report post Posted February 26, 2009 I'm using the example code to try to create a multidimensional array from a MySQL table. I'm still very new to PHP so I know I'm not constructing or parsing the array properly. Here's my code: <?php include("Includes/FusionCharts.php"); include("Includes/DBConn.php"); $IP_Addr = $_SERVER["REMOTE_ADDR"]; ?> <?php // Connect to the DB $link = connectToDB(); //$strXML will be used to store the entire XML document generated //Generate the chart element $strXML = ""; //Initialize element - necessary to generate a multi-series chart $strCategories = ""; //Initiate elements $strDataGross = ""; $strDataOwn = ""; // Fetch properties by ip $strQuery1 = "SELECT element_2 FROM ap_form_1 WHERE ip_address ='$IP_Addr' GROUP BY ip_address, element_1, element_2"; $result[1] = mysql_query($strQuery1) or die(mysql_error()); // Fetch all gross revenue records by ip $strQuery2 = "SELECT SUM(element_7) FROM ap_form_1 WHERE ip_address ='$IP_Addr' GROUP BY ip_address, element_1, element_2"; $result[2] = mysql_query($strQuery2) or die(mysql_error()); // Fetch all owner revenue records by ip $strQuery3 = "SELECT SUM(element_9) as TotOwnGrossVal FROM ap_form_1 WHERE ip_address ='$IP_Addr' GROUP BY ip_address, element_1, element_2"; $result[3] = mysql_query($strQuery3) or die(mysql_error()); //Iterate through the data foreach ($result as $resultSub) { //Append to strCategories $strCategories .= ""; //Add to both the datasets $strDataGross .= ""; $strDataOwn .= ""; } //Close element $strCategories .= ""; //Close elements $strDataGross .= ""; $strDataOwn .= ""; //Assemble the entire XML now $strXML .= $strCategories . $strDataGross . $strDataOwn . ""; //Create the chart with data from $strXML echo renderChart("charts/Column3D.swf", "", $strXML, "PropertyValue", "100%", 400, false, false); mysql_close($link); ?> Share this post Link to post Share on other sites
Paul Reyes Report post Posted February 27, 2009 $strQuery1 = "SELECT element_2 FROM ap_form_1 WHERE ip_address ='$IP_Addr' GROUP BY ip_address, element_1, element_2";$result[1] = mysql_query($strQuery1) or die(mysql_error()); You need to use mysql_result first and push the results of the query into an array. $result_num=mysql_numrows($result[1]); $i=0; while ($i < $result_num) { array_push($someVariable[1],mysql_result($result_num,$i,"<fieldname>")); $i++; } Share this post Link to post Share on other sites
billsinc Report post Posted February 27, 2009 Thanks for your help. I think I'm a little over my head with this. This is what I have and it still doesn't work. I noticed the code tags don't work so I've uploaded by code as an attachment. chart_code.txt Share this post Link to post Share on other sites
Rahul Kumar Report post Posted March 5, 2009 Hi, Sorry for late response. You could use FusionCharts_Gen.php class file by which you can directly render the chart from database. Please see the doc at http://www.fusioncharts.com/docs/Contents/PHPClassAPI/PHPClass_DB.html for more information. Share this post Link to post Share on other sites
billsinc Report post Posted March 5, 2009 Thank you, that helped and I think I'm almost there. I've got the two categories to display properly, but I can't populate the second one. I know my syntax is wrong for the IF statment, but this is what I have: $result = mysql_query($strQuery) or die(mysql_error()); // Add Categories $FC->addCategory("Property Gross Value"); $FC->addCategory("Owner Share"); if ($result) { $FC->addDatasetsFromDatabase($result, "PurDate", "TotGrossVal"); $FC->addDatasetsFromDatabase($result, "PurDate", "TotOwnShare"); } Share this post Link to post Share on other sites
Rahul Kumar Report post Posted March 6, 2009 Hi, Could you please send us the generated XML? Share this post Link to post Share on other sites
billsinc Report post Posted March 6, 2009 The code won't display so I've attached it. xml.txt Share this post Link to post Share on other sites
Rahul Kumar Report post Posted March 10, 2009 Hi, addDatasetsFromDatabase(resource $query_result, string $ctrlField, string $valueField[, array $datasetParamArray, string $link]) : FC->addDatasetsFromDatabase() fetches all datas from the database with the control break field specified at the second parameter, also this $ctrlField will be the seriesName for the chart, and $valueField will be the <set>'s value inside that datasets. Also could you please make sure that you have more than one record in the $ctrlField? Please see the documentation at http://www.fusioncharts.com/docs/Contents/PHPClassAPI/Functions.html Share this post Link to post Share on other sites