Reputation: 1
can someone inform me if there is way of generating charts from my SQL server, but not from different tables, I have one table which contain lot of column and i want to compare two or more columns choosed by the user whilst checking a checkbox. I want to put data in Multi-series charts but i dont now how it works. My following code, allow me to successfully getting the x_axis (the label value) but not my data. any suggestions ?
<?php
//We have included ../Includes/FusionCharts.php, which contains functions
//to help us easily embed the charts.
include("class/Includes/FusionCharts.php");
?>
<HTML>
<HEAD>
<TITLE> FusionCharts XT - </TITLE>
<SCRIPT LANGUAGE="Javascript" SRC="fusioncharts/fusioncharts.js"></SCRIPT>
<SCRIPT LANGUAGE="Javascript" SRC="fusioncharts/themes/fusioncharts.theme.fint.js"></SCRIPT>
</HEAD>
<BODY>
<?php
$hostdb = "localhost"; // MySQl host
$userdb = "root"; // MySQL username
$passdb = ""; // MySQL password
$dbName = "database"; // MySQL database name
$link = new mysqli ($hostdb, $userdb, $passdb, $dbName);
$strQueryCategories = "SELECT A FROM `table_temporaire` ";
$resultCategories = $link->query($strQueryCategories);
//$col="SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'chaima' AND TABLE_NAME = 'table_temporaire'";
//$r = $link->query($col);
$stmt = $link->prepare("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'database' AND TABLE_NAME = 'table_temporaire'");
$b=$stmt->execute();
$a = array();
foreach ($stmt->get_result() as $row)
{
$a[] = $row['COLUMN_NAME'];
}
$strQueryData = "SELECT * FROM `table_temporaire`";
$resultData = $link->query($strQueryData);
$strXML = "<chart legendPostion='' caption='waak' subCaption='offt' xAxisName='date' yAxisName='valeur' showValues='0' formatNumberScale='0' rotateValues='1' theme='fint'>";
$strXML .= buildCategories ($resultCategories, "A");
$strXML .= buildDatasets ( $resultData, $a, $b);
$strXML .= "</chart>";
echo renderChart("MSLine", "", $strXML, "", 600, 300, false, true);
// $resultCategories->mysqli_free_result ();
// $resultData->mysqli_free_result ();
//void mysqli_free_result ($resultData);
// mysql_free_result($resultCategories);
//mysql_free_result($resultData);
$link->close();
//mysql_close($link);
function buildCategories ( $result, $labelField ) {
$strXML = "";
if ($result) {
$strXML = "<categories>";
while($ors = $result->fetch_assoc())
{
$strXML .= "<category label='" . $ors[$labelField]. "'/>";
}
$strXML .= "</categories>";
}
return $strXML;
}
function buildDatasets ($result, $valueField, $controlBreak ) {
$strXML = "";
if ($result) {
$controlBreakValue ="";
while($ors = $result->fetch_assoc())
{
{
echo" ";
if( $controlBreakValue != $ors[$controlBreak] ) {
$controlBreakValue = $ors[$controlBreak];
$strXML .= ( $strXML =="" ? "" : "</dataset>") . ( "<dataset seriesName='" . $controlBreakValue . "'>" ) ;
$strXML .= "<set value='" . $ors[$valueField] . "'/>";
}
$strXML .= "</dataset>";
}
return $strXML;
}
?>
</BODY>
</HTML>
Upvotes: 0
Views: 848
Reputation: 53
I would do it with ajax and jquery like this:
I guess you have columns named with different car types.
+------------------------+
|ferari|lamborghini|mazda|
+------------------------+
And now you want to compare ferari specifications to mazda specifications.
I would do it like this on checked some check box with class cars, get ID of checked one. After that you can also put some info in that checkbox for ferrari, like some info that leads to ferrari specifications in database. You can make like ferrari id in database is 23, adding into checkbox data-id="23"
and then get with jquery by get elements by name data-id and send info with ajax to get contents from database. And save that one as var as active for comparing and when yu click on some other to compare to first one you can make some other scripts for equaling things up.
Upvotes: 0