Hi, I am having bit of a struggle getting the following code to work: Here are my two questions, first is there a cleaner way of dealing the 'radio button group' next is the building of a hash of hashs, and I can not seem to sort desired criteria. As a PERL neophyte all help is appreciated, Thx, Dave ------------------------------ #!/usr/bin/perl -w
my ($sort_by,$new_row ,$row_count, $first_name, $last_name, $birthday, $gender, $height, $weight); $new_row ="<tr>\n"; require "dbi-lib.pl"; require "libcgi.pl"; &initialize_dbi; &run_statement("select * from friends;"); ## Get sort order via post method &parse_input; $sort_by = $FORM_DATA{sort_order} || 0; #### %sort_order =( 0 => 'Nothing', 1 => 'Hash', 2 => 'First Name', 3 => 'Last Name', 4 => 'Birthday', 5 => 'Sex', 6 => 'Height', 7 => 'Weight', ); &print_header; # html header print <<FORM; <form method="post"> <p>Sort Database by <font color="red">$sort_order{$sort_by}</font>:</p> <p> FORM # Radio Button Group print qq/<input type="radio" name="sort_order" value="0" /; print 'checked' if ($sort_by == 0); print "> Nothing\n"; print qq/<input type="radio" name="sort_order" value="1" /; print 'checked' if ($sort_by == 1); print "> Hash\n"; print qq/<input type="radio" name="sort_order" value="2" /; print 'checked' if ($sort_by == 2); print "> First Name\n"; print qq/<input type="radio" name="sort_order" value="3" /; print 'checked' if ($sort_by == 3); print "> Last Name\n"; print qq/<input type="radio" name="sort_order" value="4" /; print 'checked' if ($sort_by == 4); print "> Birthday\n"; print qq/<input type="radio" name="sort_order" value="5" /; print 'checked' if ($sort_by == 5); print "> Sex\n"; print qq/<input type="radio" name="sort_order" value="6" /; print 'checked' if ($sort_by == 6); print "> Height\n"; print qq/<input type="radio" name="sort_order" value="7" /; print 'checked' if ($sort_by == 7); print "> Weight\n"; # End Radio Button Group print <<HEADER; </p><input type="submit" value="Sort Data"></form> <p><strong>Here is the list of your friends and their stats.</strong></p> HEADER $row_count = 0; %database = (); print <<TABLE; <table border="1" cellspacing="4" width="500"> <tr> <th>First Name</th><th>Last Name</th><th>Birthday</th><th>Sex</th><th>Height</th><th>Weight</th> </tr> TABLE while (($first_name, $last_name, $birthday, $gender, $height, $weight) = $sth->fetchrow) { # Build Hash of Hashs $database{$row_count++} = { first_name => $first_name, last_name => $last_name, birthday => $birthday, gender => $gender, height => $height, weight => $weight, }; if ($sort_by == 0){ print "$new_row\n"; print "<td>$first_name</td><td>$last_name</td><td>$birthday</td> <td>$gender</td><td>$height</td><td>$weight</td>\n"; print "</tr>\n"; } } if ($sort_by == 1){ # Sort by Hash foreach my $key (keys %database ) { &print_tableData($key); } } elsif ($sort_by == 2){ # sort by first name, does not work at this point foreach my $key (sort { $a = $database{$key}{first_name}; $b = $database{$key}{first_name}; lc($a) cmp lc($b)} keys %database){ print "<tr><td>$database{$key}{first_name}</td></tr>"; #&print_tableData($key); # &print_table_rows($key); } } *====================================================* * Cora Connection Your West African Music Source * * http://www.coraconnection.com/ * * Resources, Recordings, Instruments & More! * *====================================================* -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]