Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7308837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:37:32+00:00 2026-05-28T23:37:32+00:00

I have a form which generates an HTML table using a PHP script on

  • 0

I have a form which generates an HTML table using a PHP script on submission.

If the table looks like this…

Qty | Colour | Size  | Name
----------------------------------
10  | Red    | Small | Name 1
5   | Red    | Small | Name 2
25  | White  | Large | Name 3

…I’d like it to give information like this:

15 Red Small
25 White Large

Is this even possible as it stands using some clever PHP method I’m yet to learn? If not, and I were to use a database, would it be possible? I’d like to avoid using a database if at all possible as I don’t have database capabilities on the site it needs to be deployed on but could put it on another domain if need be.

Apologies for the lack of research effort on this one, I’m not sure where to start.

— edit to add code —

HTML

<form action="processform.php" method="post" id="monogramming-builder">
  <fieldset>
    <table>
      <tr>
        <th>Qty</th>
        <th>Colour</th>
        <th>Size</th>
        <th>Name</th>
      </tr>
      <tr>
        <td><input type="text" name="qty[]" class="qty" /></td>
        <td>
          <select name="colour[]">
            <option value="">[Please Select]</option>
            <option value="Red">Red</option>
            <option value="Black">Black</option>
            <option value="White">White</option>
          </select>
        </td>
        <td>
          <select name="size[]">
            <option value="">[Please Select]</option>
            <option value="Small">Small</option>
            <option value="Medium">Medium</option>
            <option value="Large">Large</option>
            <option value="XL">XL</option>
            <option value="2XL">2XL</option>
          </select>
        </td>
        <td><input type="text" name="name[]" maxlength="18" /></td>
      </tr>
    </table>
    <p><a href="javascript:;" class="addrow">Add a row</a></p>    
    <input type="submit" value="Send Request" />
  </fieldset>
</form>

PHP:

$qtys = $_POST['qty'];
$colours = $_POST['colour'];
$sizes = $_POST['size'];
$names = $_POST['name'];

$output = '<h2>You have requested:</h2>' . "\n";
$output .= '<table><tr><th>Qty</th><th>Colour</th><th>Size</th><th>Name</th></tr>' . "\n";
for($i=0, $count = count($qtys); $i < $count; $i++) {
  $output .= '<tr>';
  $output .= '<td>' . $qtys[$i] . '</td>' . "\n"; 
  $output .= '<td>' . $colours[$i] . '</td>' . "\n";
  $output .= '<td>' . $sizes[$i] . '</td>' . "\n";
  $output .= '<td>' . $names[$i] . '</td>' . "\n";
  $output .= '</tr>' . "\n";   
}
$output .= '</table>';  
echo $output;

JS

$('.addrow').click(function(){
    var tablerow = '<tr><td><input type="text" name="qty[]" class="qty" /></td><td><select name="colour[]"><option value="">[Please Select]</option><option value="Red">Red</option><option value="Black">Black</option><option value="White">White</option></select></td><td><select name="size[]"><option value="">[Please Select]</option><option value="Small">Small</option><option value="Medium">Medium</option><option value="Large">Large</option><option value="XL">XL</option><option value="2XL">2XL</option></select></td><td><input type="text" name="name[]" maxlength="18" /></td></tr>';
    $('tr:last-child').after(tablerow);
  });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T23:37:33+00:00Added an answer on May 28, 2026 at 11:37 pm

    I think this code or something very similar will do what you want:

    $qtys = $_POST['qty'];
    $colours = $_POST['colour'];
    $sizes = $_POST['size'];
    $names = $_POST['name'];
    
    $totals = Array();
    
    $output = '<h2>You have requested:</h2>' . "\n";
    $output .= '<table><tr><th>Qty</th><th>Colour</th><th>Size</th><th>Name</th></tr>' . "\n";
    for($i=0, $count = count($qtys); $i < $count; $i++) {
      // if we've not seen this colour before, set up an empty array
      if(!array_key_exists($colours[$i], $totals)) {
        $totals[$colours[$i]] = Array();
      }
      // if we've not seen this size for this colour before, set it to zero
      if(!array_key_exists($sizes[$i], $totals[$colours[$i]])) {
        $totals[$colours[$i]][$sizes[$i]] = 0;
      }
      // Add to the quantity for this colour/size
      $totals[$colours[$i]][$sizes[$i]] += $qtys[$i];
    
      $output .= '<tr>';
      $output .= '<td>' . $qtys[$i] . '</td>' . "\n"; 
      $output .= '<td>' . $colours[$i] . '</td>' . "\n";
      $output .= '<td>' . $sizes[$i] . '</td>' . "\n";
      $output .= '<td>' . $names[$i] . '</td>' . "\n";
      $output .= '</tr>' . "\n";   
    }
    $output .= '</table>';  
    echo $output;
    
    
    $output = "<table>";
    foreach($totals as $color=>$totals_by_size) {
      foreach($totals_by_size as $size=>$quantity) {
        $output .= '<tr>';
        $output .= '<td>'.$color.'</td>';
        $output .= '<td>'.$size.'</td>';
        $output .= '<td>'.$quantity.'</td>';
        $output .= '</tr>';
      }
    }
    echo $output.'</table>';
    

    What we do is while you’re looping over the post data to build the first table, we’re building a multi-dimensional array that looks like this:

    array(2) {
      ["red"]=>
      array(1) {
        ["Small"]=>
        int(15)
      }
      ["white"]=>
      array(1) {
        ["large"]=>
        int(25)
      }
    }
    

    Then we loop over that array and build another table to display it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this html form which calls a php file . The index.html ->
I have a PHP page which generates an HTML table. At the bottom of
I have a class that generates some html (form elements and table elements), but
I have a php file as given below. The page generates html content which
On my page I have a search form which generates a table for the
I have an HTML form generated by JSF which maps an input element to
I have an HTML table which is poulated by a user. The first colum
I have a CMS with a form-module, which generates an awful markup, that makes
I have this table where I can generate dynamic rows (which has input <type=text
I have a web page that dynamically generates form HTML via JavaScript and pours

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.