[MySQL Chart] Values being shown multiple times
FusionCharts Forum
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



[MySQL Chart] Values being shown multiple... Expand / Collapse
Author
Message
Posted 11/13/2007 5:26:21 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 11/16/2007 8:07:03 AM
Posts: 4, Visits: 8
Hello

I am trying to implement fusioncharts evaluation version with my shopping cart.

Here is the problem :
[url=http://i91.photobucket.com/albums/k283/AjnabiZ/chart.jpg][/url]

I have attached a screenshot as well.

I have trying to show "Total Sales by Customer".

I do get the total amount correctly, but it is being displayed multiple times.

Here is the PHP Code im using :


//Connect to the DB
$link = connectToDB();

//$strXML will be used to store the entire XML document generated
//Generate the chart element
$strXML = "";

//Fetch all factory records
$strQuery = "select * from va_orders";
$result = mysql_query($strQuery) or die(mysql_error());

//Iterate through each factory
if ($result) {
while($ors = mysql_fetch_array($result)) {
//Now create a second query to get details for this factory
$strQuery = "select sum(order_total) as OrderTotal from va_orders where user_id=" . $ors['user_id'];
$result2 = mysql_query($strQuery) or die(mysql_error());
$ors2 = mysql_fetch_array($result2);
//Generate
$strXML .= "";
//free the resultset
mysql_free_result($result2);
}
}
mysql_close($link);

//Finally, close element
$strXML .= "
";

//Create the chart - Pie 3D Chart with data from $strXML
echo renderChart("../FusionCharts/Column3D.swf", "", $strXML, "FactorySum", 600, 300, false, false);
?>




  Post Attachments 
chart.JPG (11 views, 23.85 KB)
Post #3025
Posted 11/13/2007 6:06:36 AM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Moderators
Last Login: Today @ 5:38:52 AM
Posts: 884, Visits: 1,420
Hi ,
 Try using this SQL query for the first SQL Query String
 
"select distinct user_id,name from va_orders"
 
YOu can even optimize the SQL to put all in a single SQL Query with out the need to second query result. We did that for demonstration purpose.
 
can use this "select  name, sum(order_total) from va_orders group by name"
The code may look like this:
 
$strQuery = "select  name, sum(order_total) from va_orders group by name";
   $result = mysql_query($strQuery) or die(mysql_error());
   
   if ($result) {
      while($ors = mysql_fetch_array($result)) {
         $strXML .= "<set label='" . $ors['name'] . "' value='" . $ors['OrderTotal'] . "' />";
         
         }
    }


Regards,

Sudipto Choudhury
FusionCharts Team
Post #3027
Posted 11/13/2007 6:47:42 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 11/16/2007 8:07:03 AM
Posts: 4, Visits: 8
Hello

Thanks alot for a quick reply as well as the fix.

I added the distinct user_id and name to the sql statement and it worked fine

Post #3029
Posted 11/16/2007 3:11:17 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 11/16/2007 8:07:03 AM
Posts: 4, Visits: 8
Hello

Can anyone tell me what settings to make when there are 1000+ customers and I need to show their totals.

The graphs will get jumbled with so many names.

Is there a way to show , let say, 10 customers , then click next to see the Next 10 and so on.
Post #3068
Posted 11/16/2007 6:25:47 AM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Moderators
Last Login: Today @ 5:38:52 AM
Posts: 884, Visits: 1,420
Hi,

This will need proper SQL Query where you can use LIMIT  

"SELECT * FROM tbl LIMIT 5,10" // this will show records fom 6 to 15

Ref : http://dev.mysql.com/doc/refman/5.0/en/select.html

Now for each press of button you can reload the chart passing the limits to another file where the XML will be created from database.

You can go through our PHP example...from Documentaion's 'Guide For Web Developers' section's -Using With PHP - PHP,JAvascript and DataURL page...for more insight on how to use that.

http://www.fusioncharts.com/docs/Contents/PHP_JS_URL.html

Regards,

Sudipto Choudhury
FusionCharts Team

Post #3070
Posted 11/16/2007 8:07:33 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 11/16/2007 8:07:03 AM
Posts: 4, Visits: 8
Sudipto Choudhury (11/16/2007)
Hi,

This will need proper SQL Query where you can use LIMIT

"SELECT * FROM tbl LIMIT 5,10" // this will show records fom 6 to 15

Ref : http://dev.mysql.com/doc/refman/5.0/en/select.html

Now for each press of button you can reload the chart passing the limits to another file where the XML will be created from database.

You can go through our PHP example...from Documentaion's 'Guide For Web Developers' section's -Using With PHP - PHP,JAvascript and DataURL page...for more insight on how to use that.

http://www.fusioncharts.com/docs/Contents/PHP_JS_URL.html


Thanks a lot

I will check it out to see it it works.
Post #3072
« Prev Topic | Next Topic »


Permissions Expand / Collapse

All times are GMT -7:00, Time now is 6:05pm


Execution: 0.125.