[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2004-04-28
7
Medium Priority
?
221 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
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

 
LVL 3

Accepted Solution

by:
cjmos earned 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

650 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