Max
Max

Reputation: 940

Looping rows in html table with php

I want to write the rows as many as the number stated in $row. (instead of one row only). How can I achieve this? What am I doing wrong? thanks.

<?php
   $row = 50;  
   echo "<table border='1'>";
   for($i=0;$i<$row;$i++)
     echo "<tr>";
        echo "<td>L1</td><td>L2</td><td>L3</td>";
      echo "</tr>";
  echo "</table>";
  echo $i+1;
    }
?>

Upvotes: 1

Views: 66

Answers (3)

Bhargav Chudasama
Bhargav Chudasama

Reputation: 7165

try this code i have added some mistake done by you

<?php
$row = 50;  
echo "<table border='1'>";
for($i=0;$i<$row;$i++){ //add bracket here
    echo "<tr>";
    echo "<td>L1</td><td>L2</td><td>L3</td>";
    echo "</tr>";
    //echo $i+1; //remove this one
}
echo "</table>"; //close table tag outside the loop
?>

Upvotes: 1

khan Farman
khan Farman

Reputation: 366

try this

<?php
       $row = 50;  
       echo "<table border='1'>";
       for($i=0;$i<$row;$i++)
       {
         echo "<tr>";
         echo "<td>L1</td><td>L2</td><td>L3</td>";
          echo "</tr>";
       }
       echo "</table>";
    ?>

Upvotes: 1

melvin
melvin

Reputation: 2621

You are closing table inside the loop. Change to the following

    <?php
       $row = 50;  
       echo "<table border='1'>";
       for($i=0;$i<$row;$i++){
         echo "<tr>";
         echo "<td>L1</td><td>L2</td><td>L3</td>";
          echo "</tr>";
       }
       echo "</table>";
    ?>

Upvotes: 3

Related Questions