Labels

php (35) javascript (31) phpjavascript (30) jquery (23) html (20) 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.

19 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
  4. Led High Bay obviously appreciate your site and you ought to write more.

    ReplyDelete
  5. Led High Bay Thanks for the great writeup. This the fact is once were some sort of pleasure bank account this.

    ReplyDelete
  6. I like to read your posts because of it's good quality.
    Visit architectural design studio!

    ReplyDelete
  7. We deliver excellence and our prices are competitive.
    As specialist web designers and website developers for London and other UK cities, we use WordPress to design, build and manage high traffic websites with fast load times to make it easy for customers to use while also boosting traffic, revenue and making the web faster for all. We deliver excellence in website design, development and SEO.

    if you want more just look here "Website design"

    ReplyDelete
  8. Thanks for sharing the valuable information. if you need to know about Web Design and Development updates or service please contact Digital Links. We are a digital marketing agency in UAE and Qatar.

    ReplyDelete
  9. Nice post.
    The best email tech support, call Roadrunner Email Tech Support Phone Number +1-888-338-6033.

    ReplyDelete
  10. Thanks for the post. Jobschampions is an online job board based in the UK providing job search and recruitment services for over 35 job sectors

    Find jobs today and apply direct to employers for jobs in the UK jobs by location:

    ReplyDelete
  11. For job search and latest job vacancies connect employers with job seekers and vice versa; skillsrecruitment we do this by helping employers and recruitment agencies advertise their job vacancies. savannarecruitment We then take these jobs to potentially suitable candidates and job seekers on-line via different devices so they can apply for latest jobs visit jobschampions , jobsonly , jobschampions.com , applytojobs , jobboss

    ReplyDelete
  12. Creating table dynamically was tough but after the explaintion and the code which you have shown here it seems easy to me. I will ret this code for my php form with POST method. Thanks for the easy code! psd to wordpress

    ReplyDelete
  13. You made some first rate points there. I seemed on the internet for the difficulty and located most people will go along with together with your website.Exide Battery Dealers in Chennai

    ReplyDelete
  14. Hello.This post was extremely fascinating, particularly because I was searching for thoughts on this issue last Tuesday. google adwords certification singapore

    ReplyDelete
  15. The accounting program comes multi-user ready and "value packs" for 3 or more users are available. Peachtree accounting software is also available in Premium and First Accounting versions.

    government grants

    ReplyDelete

More Posts

FOLLOW