in reply to Re^4: How to add columns with new row name using perl from mysql query?
in thread How to add columns with new row name using perl from mysql query?
back to your pie charts now huh?
It might help if you understood what your var data_run= statment was supposed to look like. If i remember correctly it is an array of arrays. The interior arrays contain a label and a value.
var data_run=[ ["label a",1],["label b",2],["label_c",99]];
Resultuse strict; use warnings; use DBI; my $storagefile='finddata'; my $DBH = DBI->connect( "dbi:SQLite:dbname=".$storagefile ) || die "Ca +nnot connect: $storagefile $DBI::errstr"; my $sql = 'SELECT queue_name,jobs_pend,jobs_run FROM queues ORDER BY jobs_run DESC'; my $sth = $DBH->prepare( $sql ); $sth->execute(); # input my %table = (); my $recno = 0; my @top = (); while (my ($name,$pend,$run) = $sth->fetchrow_array){ my $key = ($recno++ < 5) ? $name : 'other' ; push @top,$key unless (defined ($top[-1]) && $top[-1] eq 'other'); $table{$key}{'pend'} += $pend; $table{$key}{'run'} += $run; } #So first you need to make your interior arrays my @iarray_run; for my $key (@top){ push @iarray_run,'["'.$key.'",'.$table{$key}{'run'}.']'; } # then you join them and assign them my $orun=join(',',@iarray_run); print "var data_run=[$orun];\n";
They must be hard up for programmers where you work. It takes you days to produce something that anyone competent would do in an hour.var data_run=[["adice_short",192],["ncsim_short",84],["ncsim_long",78] +,["adice_long",39],["normal",30],["other",34]];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: How to add columns with new row name using perl from mysql query?
by Anonymous Monk on Apr 05, 2017 at 13:12 UTC | |
by huck (Prior) on Apr 05, 2017 at 13:42 UTC | |
by Anonymous Monk on Apr 05, 2017 at 15:44 UTC | |
by huck (Prior) on Apr 05, 2017 at 16:08 UTC | |
by finddata (Sexton) on Apr 06, 2017 at 05:00 UTC | |
by huck (Prior) on Apr 06, 2017 at 06:19 UTC |