1

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;
    }
?>
2
  • 1
    For starters your closing table tag in inside your loop Commented Oct 24, 2018 at 12:01
  • 2
    You missed an open bracket { just after for($i=0;$i<$row;$i++) and you don't need $i+1 Commented Oct 24, 2018 at 12:02

3 Answers 3

3

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>";
    ?>
Sign up to request clarification or add additional context in comments.

4 Comments

Parse error: syntax error, unexpected '}' on line 9. when i run this code.
@Max try now. Opening braces for for loop was missing
Thanks, I got it now.
I will accept, but I have to wait 7 minutes now. the site doesn't allow the answer to be accepted right away.
1

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>";
    ?>

Comments

1

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
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.