Labels

php (34) javascript (30) phpjavascript (29) jquery (23) html (19) mysql (14) database (9) codeigniter (4) json (4) bar chart (2) calendar (2) column chart (2) framework (2) google maps (2) query (2) tables (2) url (2) dropdown (1)

Monday, April 23, 2018

Create tables dynamically from user input using PHP

In this tutorial we are going to learn about how to generate table columns and rows dynamically from user input. 

Very simple code generate dynamic table.


Here is the code.

PHP code get requested number of columns and rows through loops and then simply display the table.

You always can make it more attractive by adding CSS styles.   



<?php
 
$createtable = '';
if ($_POST){

        $createtable .= '<table border="1">';
for ($i = 0; $i < $_POST['line']; $i++) {

$createtable .= '<tr>';
for ($j = 0; $j < $_POST['colunn']; $j++) {

$createtable .= '<td width="50">&nbsp;</td>';
}

$createtable .= '</tr>';
}

$createtable .= '</table>';
}

?>

<form action="" method="post">

<table border="0" width="200">

<tr>
<td width="80"><label>Column:</label></td>
<td width="120"><input type="text" name="colunn"></td>
</tr>

<tr>
<td><label>Line:</label></td>
<td><input type="text" name="line"></td>
</tr>

<tr>
<td colspan="2" align="right">
<input type="submit" value="Create Table">
</td>
</tr>

</table>

</form>

<?php

echo $createtable;

 ?>



For any queries or any new code requests comment below in the comment section.

3 comments:

  1. If you are going for most excellent contents like I do, simply pay a quick visit this web site all the time as it provides quality contents, thanksLed High Bay Lights

    ReplyDelete
  2. Impressive!Thanks for the post-
    For complete solution from Quick Attestation Services Pvt.Ltd. Please call on our Helpline No.9911382286 OR fill the form below :
    http://www.quickattestationservices.com/contact.html
    OR
    FOLLOW OUR FACEBOOK PAGE:
    https://www.facebook.com/QuickAServices/
    AND
    JOIN FACEBOOK GROUP :
    https://www.facebook.com/groups/220497138530592/
    OR
    TWITTER PAGE:
    https://twitter.com/QuickAServices

    ReplyDelete
  3. Wonderful Article.Enjoyed reading the article above.

    Office.com/Setup

    ReplyDelete

More Posts

FOLLOW