Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

html tables

by jwlarson3rd (Acolyte)
on Jan 10, 2004 at 01:55 UTC ( [id://320268]=perlquestion: print w/replies, xml ) Need Help??

jwlarson3rd has asked for the wisdom of the Perl Monks concerning the following question:

I would like to create a html table that is populated from a mysql table. this is I am using now and it does not create a table. the images display.
my $dat=$stht->fetchall_arrayref(); print "<table>"; print "<Tr>"; for my $i(0..$#{$dat}) { my $image = Image::Magick->new; my $in="/home/bthcraft/public_html/$nme/images/tn_$dat->[$i][2]"; my $result=$image->Read($in); warn $result if $result; my $width=$image->Get('columns'); my $height=$image->Get('rows'); print $q->start_form(-name=>'display individual',-method=>'POST',-acti +on=>'image.cgi'); print "<input type=hidden name= 'index' value='$i'>"; print "<input type=hidden name='uname' value='$nme'>"; print "<input type='image' src='http://typhoon.he.net/~bthcraft/$nme/i +mages/tn_$dat->[$i]->[2]' name='image' height ='$heigh$ print $q->end_form; print "</td>"; } print "</Tr>"; print "</table>";
this displays the images but not in a grid john larson

Replies are listed 'Best First'.
Re: html tables
by kutsu (Priest) on Jan 10, 2004 at 04:15 UTC

    I don't see a print "<td>\n";, fyi. I don't see \n anywhere for that matter, meaning your code would print in one long line. Also have you consider HTML::Template, it allows you get output normally from a database and, after pushing that into a hash, fill in the needed values in the table

    "Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce

Re: html tables
by b10m (Vicar) on Jan 10, 2004 at 04:31 UTC

    pg probably already helped you out a lot, but I'd like to point your direction to HTML::Template too (there are even Tutorials about this: HTML::Template Tutorial and Using HTML::Template). I have started working on HTML::Template a couple of days back, and must say, it's a breeze for these kind of things.

    Another thing I find perculiar about your code, is that you don't use CGI's capabilities much. For example, you could rewrite this:

    print "<input type=hidden name= 'index' value='$i'>"; print "<input type=hidden name='uname' value='$nme'>"; print "<input type='image' src='http://typhoon.he.net/~bthcraft/$nme/i +mages/tn_$dat->[$i]->[2]' name='image' height ='$heigh$

    To:

    print hidden("index",$i), hidden("uname", $nme), image_button(-name => "image", -src => "http://typhoon.he.net/~bthcraft/$nme/i +mages/tn_$dat->[$i]->[2]", -height => $height, -width => $width);

    IMO, this makes it easier to read and it's less chars to type :)

    --
    b10m
Re: html tables
by Anonymous Monk on Jan 10, 2004 at 02:05 UTC
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: html tables
by pg (Canon) on Jan 10, 2004 at 02:53 UTC
    print "<input type='image' src='http://typhoon.he.net/~bthcraft/$nme/i +mages/tn_$dat->[$i]->[2]' name='image' height ='$heigh$

    This line has a run away string, and also you have variables inside ''.

    Same for those lines, you have variables inside '':

    print "<input type=hidden name= 'index' value='$i'>"; print "<input type=hidden name='uname' value='$nme'>";

    '' prevents variables being resolved to their values. If you want ' be part of your html, escape them like this:

    my $a = 2; print "\'$a\'";

    This prints '2'

Re: html tables
by nite_man (Deacon) on Jan 10, 2004 at 19:28 UTC

    I'd suggest you to use Embperl for including Perl code into HTML page. It's very useful, simple in use and power tool. This is just example how to build HTML table and fill it data from database:

    [- $dbh = DBI->connect($DSN); $sth = $dbh->prepare("SELECT * FROM blash "); $sth->execute; $head = $sth->{NAME}; $data = $sth->fetchall_arrayref; -] <table> <tr> <th>[+ $head->[$col] +]</th> </tr> <tr> <td>[+ $data->[$row][$col] +]</td> </tr> </table>

    For more detailes, please see Embperl documentation

    Hope it helped!

    -- Michael Stepanov

Re: html tables
by fglock (Vicar) on Jan 10, 2004 at 02:18 UTC
    How about <table border=1>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://320268]
Approved by Roger
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-03-19 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found