?
Solved

creating html table using CGI.pm

Posted on 2000-03-21
5
Medium Priority
?
197 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 40 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Six Sigma Control Plans

718 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