Solved

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

Posted on 2004-04-28
7
211 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

688 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