Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2004
    Location
    Tampa
    Posts
    223
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Repeat Region PHP

    Okay, I am trying to convert from using Dreamweaver PHP to hand coding stuff and am having problems with this.

    I am trying to repeat this line of code for just the first 3 records.

    PHP Code:
     <?php do { ?><p><?php echo $row_newsinfo['newstitle']; ?></p>
                  <p><?php echo $row_newsinfo['newsbody']; ?></p>
                  <p><a href="insurance-employee-benefit-news.php?newsid=<?php echo $row_newsinfo['newsid']; ?>">Read the full story >></a></p><br>
                  <p><img src="../images/hr_small_right.jpg" width="239" height="3"></p><br><?php } while ($row_newsinfo <= 3?>

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    When you built your array $row_newsinfo, did you build more than one occurance? For example-- $row_newsinfo[0]['newstitle'] would hold the first title, $row_newsinfo[1]['newstitle'] would build the second title, and so on. Then your loop will use an iterator to get to each of the array's occurances:
    PHP Code:
    for ($i 0$i count($row_newsinfo) || $i 3$i++) {
        print 
    "<p>{$row_newsinfo[$i]['newstitle']}</p>\n";

    You could also use a foreach() but you'd have to use an iterator so why not just use a for() loop to do the iterating for you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •