Set Loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Set Loop

Post 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?
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Post 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)); ?>
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.. ;)
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Post 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?
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Post 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>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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 :)
Post Reply