title: Create html table in php using foreach() and strpos()
body: <p>A table is being built with every product/brand/condition/qty added and sent to my email. However, if one is left blank, it will destroy the table format. I have tried if/ else statements, isset/!empty, along with anything else I can think of. I want to add blank columns/ rows to insert if left blank.</p>
  
  <ul>
  <li>Since I am using a counter (product_1, product_2) with every added item and there is no limit, I am using strpos to <em>find</em> and "quickly" add to the table.</li>
  </ul>
  
  <p>-- I am unable to attach pictures with this being my first post. --</p>
  
  <p><strong>Here's what I have now and works great when no fields are left blank:</strong></p>
  
  <pre><code>$content .= "&lt;table rules='all' style='border-color: #666; width: 800px; border: 1px solid black; border-collapse: collapse; margin: 0 auto;'&gt;\r\n";    
  
  foreach($_POST as $key =&gt; $value) {
  
      $partqty = strpos($key, 'Part_Quantity');
      $partcond = strpos($key, 'Part_Condition');
      $partbrand = strpos($key, 'Part_Brand');
      $partmodel = strpos($key, 'Part_Model');
          if ($partqty === 0) {
          $content .= "&lt;tr&gt;\r\n";         
          $content .= "   &lt;td style='width:15%;'&gt;&lt;input value='" . $value . "' style='border: none; width:100%;'&gt;&lt;/td&gt;\r\n";
          }           
          if ($partcond === 0) {      
          $content .= "   &lt;td style='width:65%;'&gt;&lt;input value='" . $value . "' style='border: none; width:100%;'&gt;&lt;/td&gt;\r\n";
          }   
          if ($partbrand === 0) {
          $content .= "   &lt;td style='width:10%;'&gt;&lt;input value='" . $value . "' style='border: none; width:100%;'&gt;&lt;/td&gt;\r\n";
          }
          if ($partmodel === 0) {
          $content .= "   &lt;td style='width:10%;'&gt;&lt;input value='" . $value . "' style='border: none; width:100%;'&gt;&lt;/td&gt;\r\n";
          $content .= "&lt;/tr&gt;\r\n";            
      }
  }
  
  $content .= "&lt;/table&gt;\r\n"; 
  </code></pre>
  
  <p><strong>This is an idea of what I would like to do but doesn't work.</strong></p>
  
  <pre><code>foreach($_POST as $key =&gt; $value) {
  
      $partqty = strpos($key, 'Part_Quantity');
      $partcond = strpos($key, 'Part_Condition');
      $partbrand = strpos($key, 'Part_Brand');
      $partmodel = strpos($key, 'Part_Model');
          if ($partqty === 0) {
          $content .= "&lt;tr&gt;\r\n";         
          $content .= "   &lt;td style='width:15%;'&gt;&lt;input value='" . $value . "' style='border: none; width:100%;'&gt;&lt;/td&gt;\r\n";
          }
          if ($partqty === false) {
          $content .= "&lt;tr&gt;\r\n";         
          $content .= "   &lt;td style='width:15%;'&gt;&lt;input value='empty' style='border: none; width:100%;'&gt;&lt;/td&gt;\r\n";
          }       
          if ($partcond === 0) {      
          $content .= "   &lt;td style='width:65%;'&gt;&lt;input value='" . $value . "' style='border: none; width:100%;'&gt;&lt;/td&gt;\r\n";
          }
          if ($partcond === false) {      
          $content .= "   &lt;td style='width:65%;'&gt;&lt;input value='empty' style='border: none; width:100%;'&gt;&lt;/td&gt;\r\n";
          }
          if ($partbrand === 0) {
          $content .= "   &lt;td style='width:10%;'&gt;&lt;input value='" . $value . "' style='border: none; width:100%;'&gt;&lt;/td&gt;\r\n";
          }
          if ($partbrand === false) {
          $content .= "   &lt;td style='width:10%;'&gt;&lt;input value='empty' style='border: none; width:100%;'&gt;&lt;/td&gt;\r\n";
          }
          if ($partmodel === 0) {
          $content .= "   &lt;td style='width:10%;'&gt;&lt;input value='" . $value . "' style='border: none; width:100%;'&gt;&lt;/td&gt;\r\n";
          $content .= "&lt;/tr&gt;\r\n";            
      }
          if ($partmodel === false) {
          $content .= "   &lt;td style='width:10%;'&gt;&lt;input value='empty' style='border: none; width:100%;'&gt;&lt;/td&gt;\r\n";
          $content .= "&lt;/tr&gt;\r\n";            
      }
  }
  </code></pre>
  
  <p>Print_r example :</p>
  
  <pre><code>Array (
    [Part_Quantity_1] =&gt; 1
    [Part_Condition_1] =&gt; New
    [Part_Brand_1] =&gt; brand1
    [Part_Model_1] =&gt; model1
    [Part_Quantity_2] =&gt; 2
    [Part_Condition_2] =&gt; New
    [Part_Brand_2] =&gt; 2
    [Part_Model_2] =&gt; 2
    [Estimated_Total] =&gt; 0
    [Estimated_Hours] =&gt; 0
    [Name] =&gt; JohnDoe
    [Email] =&gt; test@test.com
    [Email_Verify] =&gt; test@test.com
    [Confirmation] =&gt; I agree
    [NameID] =&gt; form2-name
    [EmailID] =&gt; form2-email
    [HoursID] =&gt; form2-hours
    [AjaxCall] =&gt; form2_ajax
  )
  </code></pre>