|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Okay:
The code below is what I am using to display a picture and brief description out of a text file. I have no trouble in getting it to work with one record per row. What I am trying to do is make more than one record display per row. It would look like this: Image | Desc Image| Desc Image | Desc Image| Desc Image | Desc Image| Desc Instead of: Image| Desc Image| Desc Image| Desc Image| Desc Image| Desc The code below is what I am using, and it does display more than one item per row, but it is displaying the same record 3 times per row. I am lost. I have been trying everything I know, but being new to PERL is killing me. Any assistance would be much appreciated. =================== &open_file("LIST","",$list); $ticker = 0; foreach $line (sort(sort_func &read_file("LIST"))) { @tabledata =split(/\s*\|\s*/,$line ,$fields); &read_listings; $test="/img/pic$index.gif"; if (-e $test){ $photo= "/img/pic$index.gif"; } else { $photo="/img/none.gif"; } if (($price >= $FORM{'low'}|| $FORM{'low'} eq "") && ($price <= $FORM{'high'}|| $FORM{'high'} eq "")){ print "<tr>"; $i = 0; $counter = 0; while ($i < 3){ $counter = $counter + 1; &print_record; $i = $i + 1; } print "</tr>"; $ticker++; } } close(LISTINGS); sub print_record { print "<TD bgcolor=\"#FFFFFF\"><font size=\"2\" valign=\"top\"><A HREF=\"detail.pl?id=$id\"><img src=\"$photo\" border=\"0\" width=\"125\" height=\"85\"></a></TD>\n"; print "<TD bgcolor=\"#FFFFFF\"><font size=\"2\" valign=\"top\"><P ALIGN=\"left\"><b><i><font color=red><big>$desc</big></font></i></b><br>$loc<br>\$$prc<br><A HREF=\"detail.pl?id=$id\">Details</a></p></TD>\n"; } |
|
#2
|
||||
|
||||
|
while ($i < 3){ $counter = $counter + 1; &print_record; $i = $i + 1; } This while loop is giving you the trouble.Because of this the record is printed 3 times.you may need to remove that while loop. if (($price >= $FORM{'low'}|| $FORM{'low'} eq "") && ($price <= $FORM{'high'}|| $FORM{'high'} eq "")){ print "<tr>"; $i = 0; $counter = 0; while ($i < 3){ $counter = $counter + 1; &print_record; $i = $i + 1; } print "</tr>"; $ticker++; } Why you are using these many increment variable here. also try to write some comments after each line otherwise it might be very difficult for others to understand the code. Try a similar logic like following... &open_file("LIST","",$list); $ticker = 0; foreach $line (sort(sort_func &read_file("LIST"))) { @tabledata =split(/\s*\|\s*/,$line ,$fields); &read_listings; $test="/img/pic$index.gif"; if (-e $test){ $photo= "/img/pic$index.gif"; } else { $photo="/img/none.gif"; } print "<tr>"; # start the table row. if (($price >= $FORM{'low'}|| $FORM{'low'} eq "") && ($price <= $FORM{'high'}|| $FORM{'high'} eq "")){ $i = $i + 1; #increment the variable &print_record; if($i==2){ #if two columns printed then close the table row. print "</tr>"; $i = 0; } $ticker++; } } close(LISTINGS);
__________________
SR - webshiju.com www.lizratechnologies.com "The fear of the LORD is the beginning of knowledge..." |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Creating more than one column of separate data per line |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|