Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function in table

Status
Not open for further replies.

WijnandW

Technical User
Feb 2, 2003
4
NL
Hi all.

I'm experimenting with perl/CGI and now I want to create a menu for my webpage from a database.

I have following code:

sub print_menu
{
print table ( { -class=>'appletwidth'},
Tr (
td ( p ({ -class=>'applettitle' }, "Hoofdmenu" ),
get_menu()
)
)
);
}

sub get_menu
{
my $dbh=dbconnect::connect();
my $stmt = qq{ SELECT * from menu };
$sth = $dbh->prepare ($stmt);
$sth->execute ();
while ( my $row = $sth->fetchrow_hashref ())
{
print Tr ( td ( a ({href => "$row->{url}"}, "$row->{name}")));
}
}

Why are the links in my menu printed outside the table?
Is it impossible to have you own function inside a table that adds some table rows?
Or is this the wrong way?
 
Look at the HTML:

<TABLE>
<TR><TD>
<tr><td><a href=&quot;&quot;>link</a></td></tr>
</TD></TR>
</TABLE>

Your inner <tr></tr> (lower case = in the function) is not bound by a table, it is held within a table cell, <TD></TD> (upper case - outside the function). As this isn't correct HTML, browsers will have different methods of attempting to render what they think you mean.

Barbie
Leader of Birmingham Perl Mongers
 
Thanks for your answer missbarbell.
In the meanwhile I tried this:

sub print_menu
{
print start_table ( { -class=>'appletwidth'});
print Tr ( td ( p ({ -class=>'applettitle' }, &quot;Hoofdmenu&quot; )));
get_menu();
print end_table;
}

sub get_menu
{
my $dbh=dbconnect::connect();
my $stmt = qq{ SELECT * from menu };
$sth = $dbh->prepare ($stmt);
$sth->execute ();
while ( my $row = $sth->fetchrow_hashref ())
{
print Tr ( td ( a ({href => &quot;$row->{url}&quot;}, &quot;$row->{name}&quot;))),br();
}
}

I already found out that you really have to use the start and end functions when you are creating nested items so right now I am rewriting my functions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top