Hi,
Can anyone show me how to shorten the following snipit of code?
There must be a way to do it without having all the elsif clauses repeating the same html.
@addresses contains from 0 to 40 table columns like -
<td width=\"215\" align=\"center\" valign=\"middle\"><img src=$image_address></td>
but the number of columns varies each time and may not always be an even number.
I want to end up with 2 images and the two spacing columns in each row (except for the last if we have an odd number).
Any help would be most appreciated.
Thank you.
>>> Code Snipit Start <<<
$number_of_columns=@addresses;
#for each two colums in @addresses generate one complete table row
if (($number_of_columns==1) || ($number_of_columns==2)) {
$output=<<PICTURE_LESSON;
<tr>
$addresses[0]
<td width="5"> </td>
$addresses[1]
<td width="5"> </td>
</tr>
PICTURE_LESSON
return $output;
}
elsif (($number_of_columns==3) || ($number_of_columns==4)){
$output=<<PICTURE_LESSON;
<tr>
$addresses[0]
<td width="5"> </td>
$addresses[1]
<td width="5"> </td>
</tr>
<tr>
<td width="215"> </td>
<td width="5"> </td>
<td width="215"> </td>
<td width="5"> </td>
</tr>
<tr>
$addresses[2]
<td width="5"> </td>
$addresses[3]
<td width="5"> </td>
</tr>
PICTURE_LESSON
return $output;
}
# etc. etc. for up to 20 table columns
else {
$output=<<PICTURE_LESSON;
<tr>
<td width="215"> </td>
<td width="5"> </td>
<td width="215"> </td>
<td width="5"> </td>
</tr>
PICTURE_LESSON
return $output;
}
>>> Code Snipit End <<<
Can anyone show me how to shorten the following snipit of code?
There must be a way to do it without having all the elsif clauses repeating the same html.
@addresses contains from 0 to 40 table columns like -
<td width=\"215\" align=\"center\" valign=\"middle\"><img src=$image_address></td>
but the number of columns varies each time and may not always be an even number.
I want to end up with 2 images and the two spacing columns in each row (except for the last if we have an odd number).
Any help would be most appreciated.
Thank you.
>>> Code Snipit Start <<<
$number_of_columns=@addresses;
#for each two colums in @addresses generate one complete table row
if (($number_of_columns==1) || ($number_of_columns==2)) {
$output=<<PICTURE_LESSON;
<tr>
$addresses[0]
<td width="5"> </td>
$addresses[1]
<td width="5"> </td>
</tr>
PICTURE_LESSON
return $output;
}
elsif (($number_of_columns==3) || ($number_of_columns==4)){
$output=<<PICTURE_LESSON;
<tr>
$addresses[0]
<td width="5"> </td>
$addresses[1]
<td width="5"> </td>
</tr>
<tr>
<td width="215"> </td>
<td width="5"> </td>
<td width="215"> </td>
<td width="5"> </td>
</tr>
<tr>
$addresses[2]
<td width="5"> </td>
$addresses[3]
<td width="5"> </td>
</tr>
PICTURE_LESSON
return $output;
}
# etc. etc. for up to 20 table columns
else {
$output=<<PICTURE_LESSON;
<tr>
<td width="215"> </td>
<td width="5"> </td>
<td width="215"> </td>
<td width="5"> </td>
</tr>
PICTURE_LESSON
return $output;
}
>>> Code Snipit End <<<