Solved

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

Posted on 2004-04-28
7
208 Views
Last Modified: 2013-12-25
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
Comment
Question by:ronan_40060
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 3

Expert Comment

by:cjmos
ID: 10948326
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
 
LVL 9

Author Comment

by:ronan_40060
ID: 10948476
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
 
LVL 9

Author Comment

by:ronan_40060
ID: 10948490
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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 3

Accepted Solution

by:
cjmos earned 500 total points
ID: 10948583
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
 
LVL 9

Author Comment

by:ronan_40060
ID: 10949107
thanks cjmos
it worked
:)
0
 
LVL 3

Expert Comment

by:cjmos
ID: 10949131
no probs, glad to help.
0
 
LVL 9

Author Comment

by:ronan_40060
ID: 10949372
:)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Gotten a bit confused with my rather simple PowerShell script 3 41
AWK Code gives empty file, why? 12 62
size of file 1 36
global Variable - 2 functions in powershell 1 44
Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to count occurrences of each item in an array.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question