Forums
This topic is locked
looping images
Posted 21 Aug 2001 17:33:21
1
has voted
21 Aug 2001 17:33:21 Keith Slater posted:
I'm so frusterated with all this looping images and making them come out right. I've tried different scripts that you gave me tim but I cant get them to run rightThis is what I have now:
<table width="741" cellspacing="0" cellpadding="0">
<?php while (($Repeat1__numRows-- != 0) && (!$Recordset1->EOF))
{
?>
<tr>
<?php
$theLoop=0;
while (($theLoop < 2) && (!$Recordset1->EOF)) {
$theLoop++;
?>
<td width="85"><a href="obit.php?name=<?php echo $Recordset1->Fields("name"?>"><img src="images/<?php echo $Recordset1->Fields("picture"?>" width="75" height="75" border="0"></a></td>
<td width="285"><b><i><font size="3" color="#003366" face="Geneva, Arial, Helvetica, san-serif">
<?php echo $Recordset1->Fields("name"?>
<br>
</font></i></b><font size="2" color="#003366" face="Geneva, Arial, Helvetica, san-serif">
<?php echo $Recordset1->Fields("born"?>
-
<?php echo $Recordset1->Fields("died"?>
<br>
<?php echo $Recordset1->Fields("city"?>
,
<?php echo $Recordset1->Fields("state"?>
</font></td>
<td width="85"> </td>
<td width="285"> </td>
<?php
$Recordset1->MoveNext();
}
?></tr>
<?php
$Repeat1__index++;
$Recordset1->MoveNext();
}
?>
</table>
it works but not right. It shows the first 2 and it skips the third one and I'm not sure why.
thanks for the help
keith
Keith Slater
Replies
Replied 21 Aug 2001 23:40:43
21 Aug 2001 23:40:43 Bruno Mairlot replied:
Keithslater,
correct me if I'm wrong, but your code shows a little problem :
You're trying to use two loop and use a small counter to loop horizontally then loop again vertically.
I wouldn't do it that way at all.
Usually I use a simple condition based on modulus.
Here is how I'd do it : (The red part is mine)
<pre id=code><font face=courier size=2 id=code>
<table width="741" cellspacing="0" cellpadding="0">
<?php
while (($Repeat1__numRows-- != 0) && (!$Recordset1->EOF))
{
?>
<font color=red><?php
if($Repeat1_index%2==0){
?></font id=red>
<tr>
<font color=red><?php
}
?></font id=red>
<td width="85"><a href="obit.php?name=<?php echo $Recordset1->Fields("name"?>"><img src="images/<?php echo $Recordset1->Fields("picture"?>" width="75" height="75" border="0"></a></td>
<td width="285"><b><i><font size="3" color="#003366" face="Geneva, Arial, Helvetica, san-serif">
<?php echo $Recordset1->Fields("name"?>
<br>
</font></i></b><font size="2" color="#003366" face="Geneva, Arial, Helvetica, san-serif">
<?php echo $Recordset1->Fields("born"?>
-
<?php echo $Recordset1->Fields("died"?>
<br>
<?php echo $Recordset1->Fields("city"?>
,
<?php echo $Recordset1->Fields("state"?>
</font></td>
<td width="85"> </td>
<td width="285"> </td>
<font color=red><?php
if($Repeat1_index%2==1){</font id=red>
</tr>
<font color=red><?php
}
?>
<?php</font id=red>
$Repeat1__index++;
$Recordset1->MoveNext();
}
?>
</table>
</font id=code></pre id=code>
The goal here is to make PHP print the
- beginning only if the line number is a multiple of 2 (even if 0 isn't a multiple of 2)
- end of line only if the line number is a multiple of 2 -1.
If you want to show <i>n</i> pictures a line, you should use at the end of line condition :
if($Repeat1_index%<i>n</i>==<i>n-1</i>{
"First they laugh at you, then they fight you, then you Win..." Ghandi
correct me if I'm wrong, but your code shows a little problem :
You're trying to use two loop and use a small counter to loop horizontally then loop again vertically.
I wouldn't do it that way at all.
Usually I use a simple condition based on modulus.
Here is how I'd do it : (The red part is mine)
<pre id=code><font face=courier size=2 id=code>
<table width="741" cellspacing="0" cellpadding="0">
<?php
while (($Repeat1__numRows-- != 0) && (!$Recordset1->EOF))
{
?>
<font color=red><?php
if($Repeat1_index%2==0){
?></font id=red>
<tr>
<font color=red><?php
}
?></font id=red>
<td width="85"><a href="obit.php?name=<?php echo $Recordset1->Fields("name"?>"><img src="images/<?php echo $Recordset1->Fields("picture"?>" width="75" height="75" border="0"></a></td>
<td width="285"><b><i><font size="3" color="#003366" face="Geneva, Arial, Helvetica, san-serif">
<?php echo $Recordset1->Fields("name"?>
<br>
</font></i></b><font size="2" color="#003366" face="Geneva, Arial, Helvetica, san-serif">
<?php echo $Recordset1->Fields("born"?>
-
<?php echo $Recordset1->Fields("died"?>
<br>
<?php echo $Recordset1->Fields("city"?>
,
<?php echo $Recordset1->Fields("state"?>
</font></td>
<td width="85"> </td>
<td width="285"> </td>
<font color=red><?php
if($Repeat1_index%2==1){</font id=red>
</tr>
<font color=red><?php
}
?>
<?php</font id=red>
$Repeat1__index++;
$Recordset1->MoveNext();
}
?>
</table>
</font id=code></pre id=code>
The goal here is to make PHP print the
- beginning only if the line number is a multiple of 2 (even if 0 isn't a multiple of 2)
- end of line only if the line number is a multiple of 2 -1.
If you want to show <i>n</i> pictures a line, you should use at the end of line condition :
if($Repeat1_index%<i>n</i>==<i>n-1</i>{
"First they laugh at you, then they fight you, then you Win..." Ghandi
Replied 21 Aug 2001 23:44:12
21 Aug 2001 23:44:12 Bruno Mairlot replied:
Oups, there's a small mistyping at then end of the code.
And should be this instead :
<?php
if($Repeat1_index%2==1){
?>
</tr>
<?php
}
?>
"First they laugh at you, then they fight you, then you Win..." Ghandi
And should be this instead :
<?php
if($Repeat1_index%2==1){
?>
</tr>
<?php
}
?>
"First they laugh at you, then they fight you, then you Win..." Ghandi