Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Thanks

The second example was very close to what I want, as sizes aren't always 1,2,3,4 there might be a skipped size some where so I had to alter it a little bit

Here's my modified code:

my %table; my %sizes; for ( # SELECT qty, size, price [1, 100, 1, 43 ], [2, 250, 1, 52 ], [3, 100, 2, 45 ], [4, 250, 2, 55 ], [5, 100, 3, 50 ], [6, 250, 3, 56 ], [7, 200, 4, 55 ], [8, 250, 5, 61 ], ) { my ($id,$qty, $size, $price) = @$_; $table{$qty}[$size] = { 'id' => $id, 'price' => $price }; $sizes{$size}++; } print("<table border='1'>"); print("<tr>"); print("<th></th>"); print("<th>Sizes</th>"); print("</tr>"); print("<tr>"); print("<th>QTY"); for my $size (sort {$a <=> $b } keys %sizes) { print("<th>$size"); } for my $qty (sort { $a <=> $b } keys(%table)) { print("<tr>"); print("<th>$qty"); for my $size (sort {$a <=> $b } keys %sizes) { print("<td>", defined($table{$qty}[$size]) ? "<a href='$table{$q +ty}[$size]->{id}'>\$$table{$qty}[$size]->{price}</a>" : ''); } } print("</table>");
Please give me your thoughts

Thanks in advance.


In reply to Re^2: X, Y Table structure by Anonymous Monk
in thread X, Y Table structure by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-03-29 02:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found