Solved

creating html table using CGI.pm

Posted on 2000-03-21
5
185 Views
Last Modified: 2010-03-05
Hi there,

I am using CGI.pm with perl 5.004 for my CGI program. I am having some problem for writing

<TABLE BORDER="0" WIDTH="800">
      <TR>
            <TD WIDTH="160">&nbsp;</TD>
            <TD WIDTH="208">&nbsp;</TD>
            <TD WIDTH="160">&nbsp;</TD>
            <TD WIDTH="272">
            <B>Selected Analysts</B>
            </TD>
      </TR> </TABLE>

using table, Tr and td functions of CGI object. I checked some of the sample programs. But I could not find any example explaining how to create a table with different column widths as I require. I tried some stuff, but it gives compilation errors which are very ambigious.
I would appreciate if anybody can give some pointers.

Maha


0
Comment
Question by:maha
[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
5 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 2641576
do you want to print the tables using the CGI.pm functions only?

you can use the print statement for the same without having to worry about errors..

Eg.

print qq{
<TABLE BORDER="0" WIDTH="800">
                   <TR>
                   <TD WIDTH="160">&nbsp;</TD>
                   <TD WIDTH="208">&nbsp;</TD>
                   <TD WIDTH="160">&nbsp;</TD>
                   <TD WIDTH="272">
                   <B>Selected Analysts</B>
                   </TD>
                   </TR> </TABLE>

};

now you dont have to worry about escaping the quotes too. just put the code as if you were writing a plain HTML file!!

0
 

Author Comment

by:maha
ID: 2642248
Hi there,

Yes that is true;

currently I am doing like

print <<EOF;

<TABLE BORDER="0" WIDTH="800">
                   <TR>
                   <TD WIDTH="160">&nbsp;</TD>
                   <TD WIDTH="208">&nbsp;</TD>
                   <TD WIDTH="160">&nbsp;</TD>
                   <TD WIDTH="272">
                   <B>Selected Analysts</B>
                   </TD>
                   </TR> </TABLE>
EOF


It works fine. But it is static data. My table rows will be dynamically generated based on database rows.  I can use multiple prints to create table. But I just want an elegant mechanism to do it. table, Tr and td provides that, but i could not be able to set different column widths.

Regards,
Maha
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2642295
but would you sacrifice core functionality for elegance??
0
 
LVL 84

Accepted Solution

by:
ozo earned 10 total points
ID: 2642445
print table({border=>0,width=>800},"\n",
    Tr( "\n",
        (map{td({width=>$_},"&nbsp;"),"\n"} (160,208,160)),
        td({width=>272},"\n",
            b("Selected Analysts"),"\n"
        ),"\n"
    )
);
0
 

Expert Comment

by:moonlx
ID: 2643958
use CGI;
my $query = new CGI;
print $query->header();
print "<HTML><HEAD></HEAD><BODY>";
#create your headings for your table
print "<TABLE BORDER=1 WIDTH=800>
<TR>
<TD WIDTH=160>&nbsp;</TD>
<TD WIDTH=208>&nbsp;</TD>
<TD WIDTH=160>&nbsp;</TD>
<TD WIDTH=272>
<B>Selected Analysts</B>
</TD>
</TR>";

# your select statement - whatever #method you are using, for example
$res = executeQuery("SELECT * FROM table");      
# fetch the rows (1 at a time), the #while condition is my method of the #rows, substitute with your own method

while($Data = fetchRow($res))
{
#dynamically display the data, the #getItem is my method of getting the #values in the database columns, #substitute this for whatever method #you are using

print" <TR><TD WIDTH=160>".getItem($Data,"column1")."</TD><TD WIDTH=208>".getItem($Data,"column2")."</TD><TD WIDTH=160>".getItem($Data,"column3")."</TD><TD WIDTH=272><FONT class=Label>".getItem($Data,"column4")."</TD></TR>";
}
                  
print"</TABLE></DIR></BODY></HTML>";
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to join two different databases in one sql select statement in Perl using DBI? 9 68
perl script help 12 106
Reading fields from the text file. 4 104
PERL variable conundrum 9 95
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

763 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