in reply to Re: Using the mysql database columns as the table header.
in thread Using the mysql database columns as the table header.

I am trying the start_table approach as suggested by Spenser. So I decieded to just create a simple table using this method before I try to create one with a while loop embedded in it. I have this much written and it compiles but my table is just a line in the center. The data is not being written to the table can you tell me why?
print $query->header(); print $query->start_html (-title=>'Roster of Players', -style=>{'src'=>'/CSS/stylesheet.css'}); print $query->h1({-align=>'center'}, '1990 MNLIGHTNING ROSTER'); print $query->start_table({-ALIGN=>'CENTER', BORDER=>''}),"\n"; print $query->start_Tr({-bgcolor=>'#99FF99', -valign=>'TOP', -a +lign=>'center'}); print $query->start_th({-width=>'150', -align=>'center', -cols +pan=>'2'}, 'COACHING STAFF','\n'); print $query->start_td({-width=>'150', -align=>'center', -co +lspan=>'2'}, 'HEAD COACH', 'Mike Schlagel','\n', 'ASST COACH', 'Jeff Jensen', '\n', 'ASST COACH', 'Lou Skarda', '\n', 'MANAGER', 'Chris Borer'); print $query->end_td; print $query->end_th; print $query->end_Tr; print $query->end_table; print $query->end_html;

Replies are listed 'Best First'.
Re: Using the mysql database columns as the table header.
by Spenser (Friar) on Dec 28, 2001 at 03:37 UTC

    The start_td command is just like the <TD> command in raw HTML:  it doesn't contain actual text, just property settings like "align=left."  So, your code should look like this for a table data cell:

    print $query->start_th({-width=>'150', -align=>'center', -colspan=>'2'}), "COACHING STAFF","\n", $query->end_th;

    Of course, I'm not an expert at the CGI.pm and could very well be wrong about including text in the start_th.  But if you include the text in the directive, you may get yourself into the situation you were in before of directives getting intertwined with your while statement.  In short, I'm not giving you advanced advice here, but simple and managable ideas for keeping your sanity.  So, feel free to ignore me, as others will probably trump my post.

    That's Spenser, with an "s" like the detective.

      Why does this code not print the links below the table?
      print $query->table({-ALIGN=>'CENTER', BORDER=>''}, Tr({-bgcolor=>'#9933FF', -valign=>'TOP'}, [ th({-width=>'20%', -align=>'center'}, 'PLAYER NAME').th({-widt +h=>'30%', -align=>'center'}, 'ADDRESS').th({-width=>'20%', -al ign=>'center'}, 'PHONE NUMBER').th({-width=>'200', -align=>'center'}, +'FATHER').th({-width=>'200', -align=>'center'}, 'MOTHER').th({ -width=>'100', -align=>'center'}, 'DATE OF BIRTH').th({-width=>'100', +-align=>'center'}, 'ASSOCIATION').th({-width=>'50', -align=>'c enter'}, 'NUMBER').th({-width=>'50', -align=>'center'}, 'POSITION').th +({-width=>'25', -align=>'center'}, 'SHOOTS'), ] ) ); while (my @val = $sth->fetchrow_array ()) { print $query->table({-ALIGN=>'CENTER', BORDER=>''}, Tr({-bgcolor=>'#99FF99', -valign=>'TOP'}, [ td({-width=>'20%', -align=>'center'}, $val[0]).td({-width=>'30 +%', -align=>'center'}, $val[1]).td({-width=>'20%', -align=>'ce nter'}, $val[2]).td({-width=>'200', -align=>'center'}, $val[3]).td({-w +idth=>'200', -align=>'center'}, $val[4]).td({-width=>'100', -a lign=>'center'}, $val[5]).td({-width=>'100', -align=>'center'}, $val[6 +]).td({-width=>'50', -align=>'center'}, $val[7]).td({-width=>' 50', -align=>'center'}, $val[8]).td({-width=>'25', -align=>'center'}, +$val[9]), ] ) ); print $query->end_html(); } $query->start_table({-ALIGN=>'CENTER',}), $query->start_Tr({-bgcolor=>'#9933FF', -valign=>'TOP', -align= +>'center'}), $query->start_th({-align=>'center',}), "PLAYER NAME", $query->start_th({-align=>'center',}), "ADDRESS", $query->start_th({-align=>'center',}), "PHONE NUMBER", $query->start_th({-align=>'center',}), "FATHER", $query->start_th({-align=>'center',}), "MOTHER", $query->start_th({-align=>'center',}), "BIRTH-DATE", $query->start_th({-align=>'center',}), "ASSOCIATION", $query->start_th({-align=>'center',}), "NUMBER", $query->start_th({-align=>'center',}), "POSITION", $query->start_th({-align=>'center',}), "SHOOTS", $query->end_th, $query->end_Tr; while (my @val = $sth->fetchrow_array ()) { print $query->start_Tr({-bgcolor=>'#99FF99', -valign=>'TOP', -align= +>'center'}), $query->start_td({-align=>'center',}), $val[0], $query->start_td({-align=>'center',}), $val[1], $query->start_td({-align=>'center',}), $val[2], $query->start_td({-align=>'center',}), $val[3], $query->start_td({-align=>'center',}), $val[4], $query->start_td({-align=>'center',}), $val[5], $query->start_td({-align=>'center',}), $val[6], $query->start_td({-align=>'center',}), $val[7], $query->start_td({-align=>'center',}), $val[8], $query->start_td({-align=>'center',}), $val[9], $query->end_Tr; } $query->end_table, $query->a({-href=>'Roster.pl'}, h2('ROSTER'),), print $query->end_html;

        Try enclosing your variables within double-quotes:

        $query->start_td({-align=>'center',}), "$val[0]",

        That's Spenser, with an "s" like the detective.