Page 1 of 1

google chart php state_array code

Posted: Thu Dec 03, 2020 12:55 pm
by fedeocchio
Hi everybody and thanks for nuBuilder forte platform. It's fantastic!

Question: to insert a google chart into a module

where can I copy php code showed into youtube tutorial ?
https://www.youtube.com/watch?v=7B2aWPcNX9Q

I've tryed searching into this forum, ma no positive results.

Can you help me?

Thanks in advance.

Re: google chart php state_array code

Posted: Thu Dec 03, 2020 1:26 pm
by kev1n
Hi,

With OCR I extracted the code from the video. Then I did some manual corrections:

Code: Select all

$s = "SELECT COUNT(*) AS state_num, state FROM dataset GROUP BY state ORDER BY state_num ASC";
$t = nuRunQuery($s);

$head = "";
$data = "";

while ($r = db_fetch_object($t)) {

    $head .= "'" . $r->state . "',";
    $data .= $r->state_num . ",";

}

$f = "SELECT last_name, jan_sales FROM dataset GROUP BY jan_sales ORDER BY jan_sales DESC LIMIT 8";

$m = nuRunQuery($f);
$person = "";
$dollarsjanuary = "";

while ($g = db_fetch_object($n)) {

    $person .= "'" . $g->last_name . "',";
    $dollarsjanuary .= $g->jan_sales . ",";

}

nuAddJavaScript(" 

var state_array = [
		['State',$head], 
		['Employees',$data] 
	];

var sales_array = [
		['Person',$person], 
		['January',$dollarsjanuary]
	];
	
");

Re: google chart php state_array code

Posted: Thu Dec 03, 2020 3:51 pm
by fedeocchio
good job!!!!!

it works

thank you

Re: google chart php state_array code

Posted: Thu Dec 03, 2020 4:56 pm
by fedeocchio
actually it works specifiyng state_array into JavaScript array field, using this minimal php script:

Code: Select all

$s = "SELECT COUNT(*) AS state_num, state FROM dataset GROUP BY state ORDER BY state_num ASC";
$t = nuRunQuery($s);
$head = "";
$data = "";
while ($r = db_fetch_object($t)) 
{
    $head .= "'" . $r->state . "',";
    $data .= $r->state_num . ",";
}


nuAddJavaScript("
var state_array = 
[
      ['State',$head],
      ['Employees',$data]
   ];
 
");


selecting records from a table of two text field: state_num, state

record1: s1, state1
record2: s1, state1
record3: s2, state2
.............



Instead I can't manage to create SQL string into PHP code for google chart from a table like this:

record1: picture, 2
record2: audio,1
record3: picture, 1
record4: picture, 5
.......

I would like to count how many picture, audio, .... there are.

picture: 2+1+5=8
audio: 1


"SELECT media, sum(number_media) FROM dataset GROUP BY media ORDER BY media" doesn't work

any suggestion?

thanks in advance

Re: google chart php state_array code

Posted: Thu Dec 03, 2020 6:03 pm
by Janusz

Code: Select all

SELECT  media, qty from
(select media, sum(number_media) AS qty from dataset group by media) tab1
order by tab1.media

Re: google chart php state_array code

Posted: Thu Dec 03, 2020 6:24 pm
by fedeocchio
perfect, thanks!!!!!!!

my sql working:

Code: Select all

$s = "SELECT media, quantity from (select media, sum(quantity ) AS quantity from table1 group by media) table1 order by table1.media";
$t = nuRunQuery($s);
$head = "";
$data = "";
while ($r = db_fetch_object($t)) 
{
    $head .= "'" . $r->media . "',";
    $data .= $r->quantity . ",";
}
nuAddJavaScript("
var state_array = 
[
      ['media',$head],
      ['quantity',$data]
   ];
");