Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Help with's Table commands

by swarddb (Novice)
on Jun 26, 2001 at 20:59 UTC ( #91662=perlquestion: print w/replies, xml ) Need Help??

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

I am getting the following results:
Game Name Star Wars Online Players 67000 Avg Time 4 Hrs
What i would like is:
Game Name Online Players Avg Time Star Wars 67000 4 Hrs
Please Help!! The bad code i have is:
while ( ($timestamp, $report_type, $game_name, $data_name, $data_value +) = $ora_sth->fetchrow_array) { if (($data_name eq 'min') || ($data_name eq 'time')) { +$data_value = $data_value * 1440} { %myvar =( $report_type, $data_name, $data_value, ); $dname{$report_type} = $data_name; $dvalue{$report_type} = $data_value + $dvalue{$report_ +type}; } } print $query->Tr( $query->th(["Report Name"]) ); foreach $var (keys %dvalue) { if ($var =~ m/avg_per_comp_game/) {$dvalue{$var} = $dv +alue{$var} / $counter} if ($var !~ m/unique_user/ and $counter ne 1) { print $query->Tr($query->td([$var])); print $query->Tr($query->td(["$dvalue{$var} $dname{$var}"])); } } $ora_dbh->disconnect; print $query->end_table; print "\n"; print $query->end_html; print "\n";
TIA SLWARDO -"Playing games at work is unacceptable. However, testing them is highly encouraged."

Edit - 2001-26-06 Masem - Changed title from "print output"

Replies are listed 'Best First'.
Re: print output
by arturo (Vicar) on Jun 26, 2001 at 21:14 UTC

    This is an HTML output problem. The key is in those uses you make of's HTML generation methods. What you want presumably (I'm assuming you have one row of data in your example), is a table with each column's label on the top (in the first row of that column) and each subsequent row containing the value for that entry. Here's how the HTML should look:

    <tr> <td>Game Name</td> <td>Online Players</td> <td>Avg. Time</td> </tr> <tr> <td>Star Wars</td> <td>blah</td> <td>blah</td> </tr>

    Without knowing what %dvalue holds, I'd guess that the 'offending' lines are

    print $query->Tr($query->td([$var])); print $query->Tr($query->td(["$dvalue{$var} $dname{$var}"]));

    In both cases, you're passing td an anonymous array holding a single value ($var in the first, a concatenation of two hash values in the second). That will print out a single td tag in both cases; and since you've got those wrapped in Tr calls, those end up on two different rows.

    What you're getting, in other words is

    <tr> <td> ( value of $var )</td> </tr> <tr> <td>(values of the two hash entries )</td> </tr>

    You need to work to understand how these functions work, how that code translates to HTML ( or maybe you need to understand more HTML ).

    Finally, just because *can* generate HTML doesn't mean you *need* to use it to =) Look into doing things by hand a bit, it may help out here.

    perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'
Re: print output
by Beatnik (Parson) on Jun 26, 2001 at 21:07 UTC
    You dont have a $query->start_table(). Can I assume it's there but you left it out??

    ... Quidquid perl dictum sit, altum viditur.
      left it out. It was just above what i cut =) SLWARDO
        Oki, uhm do you want it tab aligned or do you actually want a table?? In case you need a table, try enclosing the HTML tags in <CODE> next time, so people can actually see what you want :)
        If you wanted tab alignment, check \t (listed in perlop)

        ... Quidquid perl dictum sit, altum viditur.
Re: print output
by azatoth (Curate) on Jun 26, 2001 at 21:05 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://91662]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2020-07-04 06:01 GMT
Find Nodes?
    Voting Booth?

    No recent polls found