Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>#!/usr/bin/perl use strict ; use warnings; use DBI; use JSON::XS; use IO::File; use Data::Dumper::Names; use POSIX; my $json = JSON::XS-&gt;new-&gt;ascii-&gt;pretty-&gt;allow_nonref; my ( $dbname , $host , $port , $dbusername , $dbpasswd ) ; # Satisfy strict my $datasource = "dbi:mysql:database=$dbname;host=$host;port=$port"; #PERL DBI CONNECT my $dbh =DBI-&gt;connect($datasource, $dbusername, $dbpasswd) || die "Could not connect to database: $DBI::errstr"; #PREPARE THE QUERY my $query1=qq(select * from table); my $query_handle1 = $dbh-&gt;prepare($query1); #EXECUTE THE QUERY $query_handle1-&gt;execute(); my @Types = ("Type1","Type2","Type3"); my @Array1 = ("Record1","Record2","Record3","Record4"); # BEGIN modified data munching my %result ; my %Type_Pos ; @Type_Pos{@Types} = ( 0 .. $#Types ) ; # Map the type to position while( my $row = $query_handle1-&gt;fetchrow_hashref ) { if( ! exists $result{$row-&gt;{Array1}} ) { # Initialize Record with all possible types $result{$row-&gt;{Array1}} = [ map { 0 } @Types ] ; } $result{$row-&gt;{Array1}}-&gt;[$Type_Pos{$row-&gt;{Type}}] = $row-&gt;{Somevalue} ; } my @chart1_data = map { encode_json( { 'name' =&gt; $_, 'data'=&gt; $result{$_} } ) } sort keys %result ; # END modified data munching $dbh-&gt;disconnect(); #JSON OUTPUT my $chart1_data_json=encode_json( { chart1 =&gt; \@chart1_data } ); print $chart1_data_json; </code></pre> <p>This should do what you asked.<br> Instead of saving the data in an array I contruct a hash where the record is the key and an arrayref of Somevalue (in order of types) is the value.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload