Page 1 of 1
Set Loop
Posted: Fri Aug 26, 2005 8:38 pm
by AliasBDI
I am designing a looping column and row. It should loop the column 3 times then loop to next row and begin looping the column 3 more times. Here is my code:
Code: Select all
<?php $colNUM = 1; ?>
<?php do { ?>
<tr>
<?php do { ?>
<td>CONTENT</td>
<?php $colNUM = $colNUM+1; } while ($colNUM<=3) ?>
</tr>
<?php } while ($row_photosLIST = mysql_fetch_assoc($photosLIST)); ?>
<?php mysql_free_result($photosLIST); ?>
Is there a better way or is there a way to make this work ... maybe I messed up somewhere?
Posted: Fri Aug 26, 2005 8:40 pm
by AliasBDI
Nevermind ... figured out while I was proofing my post.
Code: Select all
<?php do { ?>
<?php $colNUM = 0; ?>
<tr>
<?php do { ?>
<?php $colNUM = $colNUM+1; ?>
<td>CONTENT GOES HERE</td>
<?php } while ($colNUM<=2) ?>
</tr>
<?php } while ($row_photosLIST = mysql_fetch_assoc($photosLIST)); ?>
Posted: Fri Aug 26, 2005 8:48 pm
by AliasBDI
New problem ... it loops rows as many times as the records. It is not consecutively pulling the next record. In other words, all of my content is duplicated each column and not the next record.
Code: Select all
<?php do { ?>
<?php $colNUM = 0; ?>
<tr>
<?php do { ?>
<?php $colNUM = $colNUM+1; ?>
<td>CONTENT</td>
<?php } while ($colNUM<=2) && ($row_photosLIST = mysql_fetch_assoc($photosLIST)); ?>
</tr>
<?php } while ($row_photosLIST = mysql_fetch_assoc($photosLIST)); ?>
Any ideas?
Posted: Fri Aug 26, 2005 9:03 pm
by feyd
too many ideas!
Code: Select all
<?php for(;;) {
$colNUM = 0; ?>
<tr>
<?php while($colNUM<=2 && $row_photosLIST = mysql_fetch_assoc($photosLIST)) {
$colNUM++; ?>
<td>CONTENT</td>
<?php } ?>
</tr>
<?php if($row_photosLIST === false) break;
} ?>
it's challenging to read your code when you start and stop php on every line..

Posted: Fri Aug 26, 2005 9:21 pm
by AliasBDI
I do that because of the color scheme of DreamWeaver and my lack of PHP skills. What I'm getting now is a looping column that ends on the third record. But never goes to the next row.
Maybe if I could understand your code. I search PHP.net with some of it that you used and found nothing on some things. For example, what does for(;;) mean?
Posted: Fri Aug 26, 2005 9:25 pm
by AliasBDI
Got it working! Here is the code:
Code: Select all
<?php do { ?>
<?php $colNUM = 0; ?>
<tr>
<?php do { ?>
<?php $colNUM = $colNUM+1; ?>
<td>CONTENT</td>
<?php } while ($colNUM<=2 && $row_photosLIST = mysql_fetch_assoc($photosLIST)); ?>
</tr>
Posted: Fri Aug 26, 2005 9:25 pm
by feyd
for(;;) is the fastest infinite loop. It's exactly like a normal for($i = 0; $i < 200; $i++) without all the crap in the three arguments
