endsinister has asked for the wisdom of the Perl Monks concerning the following question:
I have one script (not listed here) which writes entries to a datafile. The code below is a portion of the script that outputs that same data as a table into a template. On this output page, I want to group entries by neighborhood. Currently, every entry creates a new neighborhood group (not grouping entries with the same neighborhood together. Repeating the same neigborhood) and under each grouping lists every entry regardless of its neighborhood (Repeating information). Hmm... This may sound confusing... You can see the output in action here:
http://www.jyadvertising.com/cgi-bin/homesreadynow_index.cgi
And this is an example of how I am trying to output the page:
http://www.jyadvertising.com/cristohomes/example.html
I need your wisdom!open (FILE, "$datafile") || &fatal_error("Unable to open $datafile"); &lock(FILE); @messages = <FILE>; &unlock(FILE); close(FILE); for ($a = 0; $a < @messages; $a++) { ($mnum[$a],$maddress[$a],$mimage[$a],$mneighborhood[$a],$mmodelname[$a +],$mmodelelevation[$a],$mbedrooms[$a],$mbathrooms[$a],$mtypeoffoundat +ion[$a],$mschooldistrict[$a],$mprice[$a],$mpaymentsfrom[$a],$mreadyda +te[$a],$mphonenumber[$a],$memail[$a],$chop) = split(/``/,$messages[$a +]); } open (FILE, "$template") || &fatal_error("Unable to open $template"); &lock(FILE); @template = <FILE>; &unlock(FILE); close(FILE); for ($a = 0; $a < @template; $a++) { $_ = $template[$a]; if (/<!--messages-->/) { print "<table width=400 border=0 cellpadding=3 cellspacing=3>\ +n"; print "<tr class=\"typewhite\" bgcolor=\"#000000\">\n"; print "<td><b>Address</b></td>\n"; print "<td><b>Model Name</b></td>\n"; print "<td><b>Price</b></td>\n"; print "<td><b>Availability</b></td>\n"; print "</tr>\n"; foreach $mneighborhood (@mneighborhood) { print "<tr class=\"type\" bgcolor=\"#EEEFDD\"><td colspan= +4><a href=\"../cristohomes/hoods/$mneighborhood.shtml\" class=\"type\ +"><b>$mneighborhood</b></a></td</tr>"; for ($b = 0; $b < @messages; $b++) { print "<tr class=\"type\">\n"; print "<td><a href=\"$indexcgi$queryswitch"; print "action=display\&num=$mnum[$b]\" class=\"red\">$ +maddress[$b]</a></td>\n"; print "<td><a href=\"../cristohomes/homes/$mmodelname[ +$b].shtml\" class=\"red\">\"The $mmodelname[$b]\"</a></td>\n"; print "<td>$mprice[$b]</td>\n"; print "<td>$mreadydate[$b]</td>\n"; print "</tr>\n"; } } print "</table>\n"; } }
update (broquaint): added formatting
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help? - Trouble outputting data corectly
by jdporter (Paladin) on Dec 16, 2002 at 22:39 UTC | |
by endsinister (Initiate) on Dec 17, 2002 at 16:05 UTC | |
|
Re: Help? - Trouble outputting data corectly
by John M. Dlugosz (Monsignor) on Dec 16, 2002 at 21:58 UTC |