Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

google chart php state_array code

Questions related to nuBuilder Forte Reports and the Report Builder.
Post Reply
fedeocchio
Posts: 4
Joined: Thu Dec 03, 2020 12:50 pm

google chart php state_array code

Unread post 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.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: google chart php state_array code

Unread post 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]
	];
	
");
fedeocchio
Posts: 4
Joined: Thu Dec 03, 2020 12:50 pm

Re: google chart php state_array code

Unread post by fedeocchio »

good job!!!!!

it works

thank you
fedeocchio
Posts: 4
Joined: Thu Dec 03, 2020 12:50 pm

Re: google chart php state_array code

Unread post 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
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Re: google chart php state_array code

Unread post 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
If you like nuBuilder, please leave a review on SourceForge
fedeocchio
Posts: 4
Joined: Thu Dec 03, 2020 12:50 pm

Re: google chart php state_array code

Unread post 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]
   ];
");
Post Reply