sabecs
asked on
PHP - build javascript code using results returned from MySQL
Hi,
The records below are returned from MySQL table,
store_name year_month order_total
HeadOffice 2013-05 359.16
HeadOffice 2013-06 6.00
HeadOffice 2013-07 827.54
Sydney 2013-06 632.80
Sydney 2013-07 16.40
Sydney 2013-12 316.40
Warehouse 2013-06 9.95
Warehouse 2013-07 73.90
Warehouse 2013-10 39.95
is there anyway I can build the following using while or foreach loops?
var store1=[['2013-05', 359.16], [2013-06', 6.00], ['2013-07', 827.54], ['2013-10', 0], ['2013-12', 0]];
var store2=[['2013-05', 0], [2013-06', 632.80], ['2013-07', 16.40], ['2013-10', 0], ['2013-12', 316.40]];
var store3=[['2013-05', 0], [2013-06', 9.95], ['2013-07',73.90], ['2013-10', 39.95], ['2013-12', 0]];
do {
$year_month = $row_store_sales['$year_mo nth'];
$store_name = $row_store_sales['store_na me'];
$order_total = $row_store_sales['order_to tal'];
}while ($row_store_sales = mysql_fetch_assoc($store_s ales));
I need to get all the different year_month and check for orderrs from each store?
Thanks
The records below are returned from MySQL table,
store_name year_month order_total
HeadOffice 2013-05 359.16
HeadOffice 2013-06 6.00
HeadOffice 2013-07 827.54
Sydney 2013-06 632.80
Sydney 2013-07 16.40
Sydney 2013-12 316.40
Warehouse 2013-06 9.95
Warehouse 2013-07 73.90
Warehouse 2013-10 39.95
is there anyway I can build the following using while or foreach loops?
var store1=[['2013-05', 359.16], [2013-06', 6.00], ['2013-07', 827.54], ['2013-10', 0], ['2013-12', 0]];
var store2=[['2013-05', 0], [2013-06', 632.80], ['2013-07', 16.40], ['2013-10', 0], ['2013-12', 316.40]];
var store3=[['2013-05', 0], [2013-06', 9.95], ['2013-07',73.90], ['2013-10', 39.95], ['2013-12', 0]];
do {
$year_month = $row_store_sales['$year_mo
$store_name = $row_store_sales['store_na
$order_total = $row_store_sales['order_to
}while ($row_store_sales = mysql_fetch_assoc($store_s
I need to get all the different year_month and check for orderrs from each store?
Thanks
I'm curious what you are trying to do. While I have written PHP code that populates javascript variables, it's not the first choice if you just need to display the data on a page. PHP can do that directly.
ASKER
Thanks for your comments, I am trying to get the output from a MySQL table in a format that can be entered into http://www.jqplot.com to display charts/graphs on sales ...
Ok, that's do-able. I believe your dates will have to be converted to a simple number that represents a scale on the chart.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Julian, that is great....
You are welcome - thanks for the points.
Open in new window
To me it looks like you're copying code you found on the internet or on DreamWeaver (one of the worst possible ways to learn PHP). Why not try it from a professional perspective? Use any of the learning resources shown in this article, especially the Welling/Thompson book. It will put you light-years ahead of trial and error learning, I promise!https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html