Solved

creating html table using CGI.pm

Posted on 2000-03-21
5
183 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
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

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…

791 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