Solved

creating html table using CGI.pm

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 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

19 Experts available now in Live!

Get 1:1 Help Now