Forums

PHP

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 right

This 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>
&lt;table width="741" cellspacing="0" cellpadding="0"&gt;
&lt;?php

while (($Repeat1__numRows-- != 0) && (!$Recordset1-&gt;EOF))
{
?&gt;
<font color=red>&lt;?php
if($Repeat1_index%2==0){
?&gt;</font id=red>
&lt;tr&gt;
<font color=red>&lt;?php
}
?&gt;</font id=red>
&lt;td width="85"&gt;&lt;a href="obit.php?name=&lt;?php echo $Recordset1-&gt;Fields("name"?&gt;"&gt;&lt;img src="images/&lt;?php echo $Recordset1-&gt;Fields("picture"?&gt;" width="75" height="75" border="0"&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td width="285"&gt;&lt;b&gt;&lt;i&gt;&lt;font size="3" color="#003366" face="Geneva, Arial, Helvetica, san-serif"&gt;
&lt;?php echo $Recordset1-&gt;Fields("name"?&gt;
&lt;br&gt;
&lt;/font&gt;&lt;/i&gt;&lt;/b&gt;&lt;font size="2" color="#003366" face="Geneva, Arial, Helvetica, san-serif"&gt;
&lt;?php echo $Recordset1-&gt;Fields("born"?&gt;
-
&lt;?php echo $Recordset1-&gt;Fields("died"?&gt;
&lt;br&gt;
&lt;?php echo $Recordset1-&gt;Fields("city"?&gt;
,
&lt;?php echo $Recordset1-&gt;Fields("state"?&gt;
&lt;/font&gt;&lt;/td&gt;
&lt;td width="85"&gt; &lt;/td&gt;
&lt;td width="285"&gt; &lt;/td&gt;
<font color=red>&lt;?php
if($Repeat1_index%2==1){</font id=red>
&lt;/tr&gt;
<font color=red>&lt;?php
}
?&gt;
&lt;?php</font id=red>
$Repeat1__index++;
$Recordset1-&gt;MoveNext();
}
?&gt;
&lt;/table&gt;
</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 :

&lt;?php
if($Repeat1_index%2==1){
?&gt;
&lt;/tr&gt;
&lt;?php
}
?&gt;


"First they laugh at you, then they fight you, then you Win..." Ghandi

Reply to this topic