View Full Version : Repeat Region PHP

07-24-2007, 09:14 PM
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 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) ?>

07-25-2007, 12:40 AM
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:

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.