Jump to content

How do you repeat PHP code for a certain number of times?


johnmcg0000

Recommended Posts

How do you make php code repeat for a certain amount of times. I am only new to php and I am trying to make the code below repeat 6 times instead of repeating all the matching elements in the database. From my other coding experience I would use a for loop but as I am new to php I am not really sure how to implement the for and while loops together. I was trying to add an integer that incremented until it hit 6 and then would exit the while loop but I couldn't get it to work. This is probably a simple problem and any help would be appricated. Thanks.

 

<?php			
	$subject_set = mysql_query("Select * FROM movies WHERE media = 'Movies' ORDER BY dateadded DESC", $connection);					
	if (!$subject_set){
	die("Database connection failed: " . mysql_error());
	}		
        while ($subject = mysql_fetch_array($subject_set)){?>
          <div class="par_element">
            <div class="repeat_horizontal">
              <div class="repeat_hor_picture">
              <a href="<?=$subject['link']?>"> <img src=" <?=$subject['picture']?>" /></a>
              </div>
              <a href=" <?=$subject['link']?>"><?= $subject['title']?>.</a>
            </div>
           <?php } ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.