• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

adjustment in the code to get the result in a specific table form

I have the following code which puts the result of sql into a table

      print "<table align=\"center\" bgcolor=\"white\" border=1 bordercolor=\"blue\" >";    
      print "<tr>";
      print "<td><b>Col 1</b></td>";
      print "<td><b>Col 2</b></td>";
      print "<td><b>Col 3</b></td>";
      print "</tr>";
      while (my @row= $sth_A->fetchrow_array())
              {
             print "<tr>\n";
             foreach my $my_td (@row) { print "<td>$my_td</td>\n"; }
             print "</tr>\n";
      }
      $sth_A->finish();
      print "</table>";
      print "<br>";
      print "<table align=\"center\" bgcolor=\"white\" border=1 bordercolor=\"blue\" >";
      print "<tr>";
      print "<td><b>Total Col1 </b></td>";
      print "<td><b>Total Col2</b></td>";
      print "</tr>";
      while (my @row= $sth_B->fetchrow_array())
              {
             print "<tr>\n";
             foreach my $my_td (@row) { print "<td>$my_td</td>\n"; }
             print "</tr>\n";
      }
      $sth_B->finish();
      print "</table>";


      The result of the above code is shown as follows
 Table 1

                      Col 1                   Col 2           Col 3
           typ1                25         56
            typ2                85          48
                      typ3                87             98

Table 2
            
           total col 1           total col2
            197                   202                     

----------------------------------------------------------------------------------------------------------------------------            

Now I want the above result to be displayed like shown in below
                       
                     
                  Col 1                      Col 2           Col 3
                  typ1                25            56
                  typ2                85           48
                                      typ3                87             98
                  Total               197           202
-----------------------------------------------------------------------
any ideas
0
ronan_40060
Asked:
ronan_40060
  • 4
  • 3
1 Solution
 
cjmosCommented:
Does changing the following make any difference?

print "<tr align='left'>";
     print "<td><b>Col 1</b></td>";
     print "<td><b>Col 2</b></td>";
     print "<td><b>Col 3</b></td>";
print "</tr>";


print "<tr align='left'>\n";
           foreach my $my_td (@row) { print "<td>$my_td</td>\n"; }
print "</tr>\n";

If not, what does the source code of the page look like?
0
 
ronan_40060Author Commented:
print "<table align=\"center\" bgcolor=\"#f5deb3\" border=1 bordercolor=\"maroon\" >";    
      print "<tr>";
      print "<td><b>Type</b></td>";
      print "<td><b>Nb of Record 1 </b></td>";
      print "<td><b>Nb of Record 2 </b></td>";
      print "</tr>";
      while (my @row= $sth_A->fetchrow_array())
              {
             print "<tr>\n";
             foreach my $my_td (@row) { print "<td>$my_td</td>\n"; }
             print "</tr>\n";
      }
      $sth_A->finish();
      print "</table>";
      print "<br>";
      print "<table align=\"center\" bgcolor=\"#f5deb3\" border=1 bordercolor=\"maroon\" >";
      print "<tr>";
      print "<td><b>Total Records 1 </b></td>";
      print "<td><b>Total Records 2</b></td>";
      print "</tr>";
      while (my @row= $sth_B->fetchrow_array())
              {
             print "<tr>\n";
             foreach my $my_td (@row) { print "<td>$my_td</td>\n"; }
             print "</tr>\n";
      }
      $sth_B->finish();
      print "</table>";
      print "<br>";
      print "<br>";
      
      print "<br>";

Type Nb of Record 1 Nb of Record 2  
RTF       800             1010
DOC     3898            4030
TXT     4325            4611


Total Records 1 Total Records 2
9023               9651

Now in what I want is
the result should be displayed like

Type Nb of Record 1 Nb of Record 2  
RTF       800             1010
DOC     3898            4030
TXT     4325            4611
0
 
ronan_40060Author Commented:
Now in what I want is
the result should be displayed like

Type Nb of Record 1 Nb of Record 2  
RTF       800             1010
DOC     3898            4030
TXT     4325            4611
Total   9023             9651
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
cjmosCommented:
try:


print "<table align=\"center\" bgcolor=\"#f5deb3\" border=1 bordercolor=\"maroon\" >";    
     print "<tr>";
     print "<td><b>Type</b></td>";
     print "<td><b>Nb of Record 1 </b></td>";
     print "<td><b>Nb of Record 2 </b></td>";
     print "</tr>";
     while (my @row= $sth_A->fetchrow_array())
            {
           print "<tr>\n";
           foreach my $my_td (@row) { print "<td>$my_td</td>\n"; }
           print "</tr>\n";
     }
     $sth_A->finish();
     print "<tr><td>Total<td>";
     while (my @row= $sth_B->fetchrow_array())
                   {
                    foreach my $my_td (@row) { print "<td>$my_td</td>\n"; }
                  
     }
     print "</tr></table>";
     $sth_B->finish();
0
 
ronan_40060Author Commented:
thanks cjmos
it worked
:)
0
 
cjmosCommented:
no probs, glad to help.
0
 
ronan_40060Author Commented:
:)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now