Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 17th, 2001, 07:33 PM
amerimaxx amerimaxx is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Posts: 5 amerimaxx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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";

}

Reply With Quote
  #2  
Old April 20th, 2001, 12:52 AM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 9
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan

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..."

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Creating more than one column of separate data per line


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway