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 } ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.