开发者

php loop for a amount of times [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I need to loop a html code with php so it will display a list if messages results if it is possible?

I found this code on google? i couldnt understand it:

      $brush_price = 5; 

    echo "<table border=\"1\" align=\"center\">";
    echo "<tr><th>Quantity</th>";
    echo "<th>Price</th></tr>";
    for ( $counter = 10; $counter <= 100; $counter += 10) {
        echo "<tr><td>";
        echo $counter;
        echo "</td><td>";
        echo $brush_price * $counter;
        echo "</td></tr>";
    echo "</table>";

}

I just need it to duplicate a div which is

<div class="news" align="center" style="width:900px;height:65px;background-color:#C8C8C8">
<h3> From: ..... </h3></br&开发者_StackOverflow中文版gt;
<p1> Message: Thank you for registering... </p1>
</div>

and i need to loop it for home much messages he has


<?php
for ($i = 0; $i < 10; $i++) {
?>
    <div class="news" align="center" style="width:900px;height:65px;background-color:#C8C8C8">
    <h3> From: ..... </h3></br>
    <p1> Message: Thank you for registering... </p1>
    </div>
<?php
}
?>

Although, as @mc10 stated, <p1> is not a valid HTML tag. This code will duplicate that HTML ten times. To change the number of times it duplicates, change the number in the loop ($i < 10).

The sample code is a basic for loop, like I used here. The manual on the for control structure is here:

http://php.net/for

I recommend that you read a tutorial on the basics of PHP.

http://devzone.zend.com/article/627


This is a for loop:

for ( $counter = 10; $counter <= 100; $counter += 10) {

It starts at 10, $counter, and then will continue until that counter is greater than 100. Every time it runs that code, it will increase by ten. You can duplicate your div by putting a for loop around it like this

<?php
for( $i = 0; $i < NUMBER_OF_TIMES_TO_RUN; $i += AMOUNT_TO_ADD_EACH_TIME) {
?>
    HTML
<?php
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜