Solved

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

Posted on 2004-04-28
7
197 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
  • 4
  • 3
7 Comments
 
LVL 3

Expert Comment

by:cjmos
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Accepted Solution

by:
cjmos earned 500 total points
Comment Utility
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
Comment Utility
thanks cjmos
it worked
:)
0
 
LVL 3

Expert Comment

by:cjmos
Comment Utility
no probs, glad to help.
0
 
LVL 9

Author Comment

by:ronan_40060
Comment Utility
:)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
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…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now