Skip to content Skip to sidebar Skip to footer

Populate Dropdown Boxes While Also Populating Table

I have a table that is populated using a foreach loop. One of my columns is SKU Group, which is a column of dropdown boxes. However, whenever the foreach loop runs, only the one co

Solution 1:

first need to populate your dropdown list using loop

<?php 
 $i = 0;
 $content = '';
  $names =  array('Test1','Test2');
  foreach ($names as $row) {
  if($i== 0){  
  $names =  array('Test1','Test2');// replace it  echo $row ['SKU Group'];

  foreach($names as $key)
  {
   $content .= '<option value="'.$key.'">'.$key.'</option>';    
  }
   } 
  $i++;
  ?>

  <tr>
   <td>sadasdsa</td>
    <td class="sku_group" id="sku_group-<?php echo intval ($row['SKU Group'])?>" align="center">

    <select id="sku_group_dropdown">
    <?php echo $content?>
    </select>

     </td>
        <td><input type="button" class="edit" name="edit" value="Edit">                  </td>
       </tr>

          <?php } ?>

in this code replace your array data or if you want to populate dropdown data outside your loop then first get your group data for you can use this code


Post a Comment for "Populate Dropdown Boxes While Also Populating Table"