|
|
Question : syntax error while coding for drawing a percent graph without GDGraph module
|
|
What I am doing here is putting the result of sql_A into a graphical representation into a table where I have 3 columns i.e Domain , Total docs for a perticular domain and Percentage of docs for a single domain The graphical representation I mean the percentage column will be denoted by a a strip of #0000FF Currently I am getting a syntax error at $docrows .= Tr( td( $_ ), td( my $domain{ $_ } ), All suggestions are welcome Regards Ronan use warnings; use strict; use DBI; use CGI; use CGI::Carp qw(fatalsToBrowser); my $q = new CGI; my $percent;
my $dbh = DBI->connect( 'dbi:Oracle:host=xxxx; sid=xxxx;port=xxxx', 'xxx', 'xxx', { RaiseError => 1, AutoCommit => 0} ) || die "Database connection not made: $DBI::errstr\n";; my $sql_A=qq{ select AA.TYPE, AA.DOCS, to_char(round ((AA.DOCS/AA.TOTAL)*100,2),'9,990.0') as PERCENT from (select a.dc_type as TYPE, count(distinct c.vpd_doc_id) as DOCS, count(*) as TOTAL from domain_prj a , sdomain_prj b, v_prjdoc c, projet d where a.dc_id=b.sdc_dc_id and c.vpd_prj_id=d.prj_id and b.sdc_id= d.prj_sdc_id group by a.dc_type)AA}; my $sth_A = $dbh->prepare ($sql_A)|| die "Prepare failed: $DBI::errstr\n"; $sth_A->execute() || die "Couldn't execute query:$DBI::errstr\n"; my $results = $sth_A->fetchall_arrayref(); my $total = scalar( @$results ); my (%docs); my $docrows = Tr( th( { width => "100" }, "Domain" ), th( { width => "50" }, "Total Docs" ), th( "Percent Of Utilisation" ) ); foreach ( sort { $docs{ $b } <=> $docs{ $a } } keys( %docs ) ) { my $percent = int( $docs{ $_ } * 100 / $total ); $docrows .= Tr( td( $_ ), td( my $domain{ $_ } ), td( table( { -width => "100%" }, Tr( td( { -width => " $percent%", -bgcolor => "#0000FF" }, br ), td( br ) ) ) ) ); } print h3( { -align => "center" }, "Docs par Domaine" ), table( { -border => 1, -width => "100%" }, $docrows );
$dbh->disconnect();
|
Answer : syntax error while coding for drawing a percent graph without GDGraph module
|
|
I changed the inner loop a bit. The reason you didn't see the percentage was that we put the string in the attribute hashref for that td, where we should have replaced that last "br()".
$docrows .= Tr( td( {-width=>"20%"}, $aa_type ), td( { -width=>"5%"}, $aa_docs ), # <== I gave these td's a width as well td( table( { -width => "100%" }, # <== this table can be 100% of the width of the td it is in Tr( td( { -width => "$doc_pct%", -bgcolor => "#0000FF" }, br() ), td( { -width => (100- $doc_pct)."%", }, sprintf("%.2f%",$doc_pct) ) ) ) # <== moved the string outside the {} and rounded it to 2 decimals ) ); }
|
|
|
|
|