Click here to Skip to main content
14,695,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can we create a table dynamically in php, providing the number of columns in a text box ?
The table should be created at run time.
Plz give me the answer.
Posted
v2
Comments
ZurdoDev 19-Jul-12 14:25pm
   
Do you know php?
markkuk 20-Jul-12 5:28am
   
HTML table, SQL table or some other sort of table? Please be more specific.

1 solution

What you need to do is something like this:

<?php
$rows = 10; // define number of rows
$cols = 4;// define number of columns

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

for($tr=1;$tr<=$rows;$tr++){

    echo "<tr>";
        for($td=1;$td<=$cols;$td++){
               echo "<td>row: ".$tr." column: ".$td."</td>";
        }
    echo "</tr>";
}

echo "</table>";
?>


To receive the number of columns from a form use either the POST or GET methods.
Please refer to this tutorial: http://www.w3schools.com/php/php_get.asp[^]
   
Comments
Sandeep Mewara 20-Jul-12 16:09pm
   
My 5!
Shaunak De 21-Jul-12 1:16am
   
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900