Jump to content

populate html table with php


demanon

Recommended Posts

hello all,

i'm just beginning to learn php and needed some help with a project i've been assigned.  basically, i need a way for non-technical people to be able to create/populate multiple html tables (2 columns, maybe 4-5 rows) and html is WAAAY over their heads.  I thought to begin with I'd just create the table template with dummy text and let them update the code, but they all just looked at me with blank expressions.  What I'm looking to do is setup a simple php form that will have a few text boxes and once they fill those in and click 'submit' it will display the entire pre-formatted html table code with their entries included in the appropriate place.  that way, they'll just be able to copy the entire html table code and paste it where necessary.  any help is much appreciated.
Link to comment
Share on other sites

SOmething like this:
[code]<?php

if(isset($_POST['genCode']))
{
    // echo '<pre>' . print_r($_POST['tool'], true) . '</pre><br /><br />';

    echo '<h1>Generating HTML...</h1>';

    $html = <<<HTML

<table width="90%" border="1" cellpadding="7">
  <tr bgcolor="#66ccff">
    <td><big>"Problem/Error":</big> {$_POST['problem']}</td>
  </tr>

  <tr bgcolor="#ccffff">
    <td><big>"Cause":</big> {$_POST['cause']}</td>
  </tr>
  <tr>
    <td><big>"Solution":</big> {$_POST['solution']}</td>
  </tr>

  <tr bgcolor="#dddeee">
    <td><big>"Tools":</big>

      <table width="100%" border="1" cellpadding="7">

HTML;

    $i = 0;

    foreach($_POST['tool']['name'] as $tools => $tool)
    {
        $html .= <<<HTML
        <tr bgcolor="#dddeee">
          <td width="40%">"{$tool}"</td>
          <td>{$_POST['tool']['desc'][$i]}</td>
        </tr>

HTML;
        $i++;
    }

    $html .= <<<HTML

      </table>
    </td>
  </tr>
</table>
HTML;

    echo '<textarea cols="100" rows="20">' . $html . '</textarea>';
}
else
{
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  <table cellpadding="7" cellspacing="0" border="1" width="90%">
      <tr>
          <td><big>"Problem/Error":</big> <input name="problem" type="text" /></td>
      </tr>
      <tr>
          <td><big>"Cause":</big> <input name="cause" type="text" /></td>
      </tr>
      <tr>
          <td><big>"Solution":</big> <input name="solution" type="text" /></td>
      </tr>
      <tr>
          <td colspan="2">
            <big>"Tools":</big>
            <table align="center" width="98%" cellpadding="7" cellspacing="0" border="1" style="margin: 1%;">
                <tr>
                    <td>"Tool Name"</td>
                    <td>"Tool Description"</td>
                </tr>
                <?php
                for($i=0; $i < 5; $i++)
                {
                ?>
                <tr>
                    <td width="40%"><input name="tool[name][]" type="text" size="50" /></td>
                    <td><input name="tool[desc][]" type="text" size="80" /></td>
                </tr>
                <?php
                }
                ?>
            </table>
          </td>
      </tr>
      <tr><td colspan="2"><input type="submit" name="genCode" value="Generate HTML" /></td></tr>
  </table>
</form>
<?php
}
?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.