Skip to content Skip to sidebar Skip to footer

Output Dynamic Table Data

I am creating an invoice website for my intranet. I have the following code for making a dynamic table row inside the html that generates rows up to how much we need for the invoic

Solution 1:

You need to give the form fields names ending in []. When the form is submitted, PHP will combine all the fields with the name name[] into an array in $_POST['name']. You can then iterate through these arrays to get all the rows of the form.

The form should look something like:

<form method="post" action="your URL">
  <table>
    <tr><td><input type="text" name="somename[]"></td>
        <td><select name="somemenu[]">
              <option value="">Please choose</option>
              <option value="1">Option 1</option>
              <option value="2">Option 2</option>
              ...
            </select></td>
    </tr>
  </table>
</form>

Then your PHP can do:

foreach (array_keys($_POST['somename']) as $key) {
  // Do something with $_POST['somename'][$key] and $_POST['somemenu'][$key]
}

Post a Comment for "Output Dynamic Table Data"