php include语句只执行WHILE循环的一个实例

I thoroughly researched the topic, but my beginner coding skills are wondering why PHP renders only one line of the WHILE loop contained in the INCLUDE script.

To make your answering easy, here are the elements of my problem:

A) call to include the php script:

include ("/DEMO/HtmlTabela.php");

B) Contents of the INCLUDE script:

<?php 

$BrojRedova = 5;

echo "<table border='1'>";
echo "<tr>";

echo "<td>Pozdrav</td>";
echo "<td>Ime</td>";
echo "<td>Prezime</td>";
echo "<td>Preduzece</td>";
echo "</tr>";

// Petlja za automatsko popunjavanje redova HTML tabele upotrebom PHP-a
$brojac = 0;
while($brojac<5) {
        echo "<td>Gospodin</td>";
        echo "<td>Daniel</td>";
        echo "<td>Andric</td>";
        echo "<td>PPB</td>";
        echo "</tr>";
        $brojac++;
}

echo "</table>";

C) Result

Pozdrav Ime Prezime Preduzece Gospodin Daniel Andrić PPB

D) Problem is, I wrote the WHILE loop to get this result:

Pozdrav Ime Prezime Preduzece Gospodin Daniel Andric PPB Gospodin Daniel Andric PPB Gospodin Daniel Andric PPB Gospodin Daniel Andric PPB Gospodin Daniel Andric PPB

You need an echo('<tr>'); at the beginning of the while loop to start the table row. Examining the HTML output of your script is a great help in debugging your PHP.

There are problems with your original code.I think you forgot to place echo('<tr>'); inside while loop. You can use it like in the following code.

while($brojac<5) {
    echo('<tr>');
    echo "<td>Gospodin</td>";
    echo "<td>Daniel</td>";
    echo "<td>Andric</td>";
    echo "<td>PPB</td>";
    echo "</tr>";
    $brojac++;
}