0

Is there anyway that i can make the code i have with another for loop that creates the actual select box for each column title?

I have the forloop in place for the information in the database but not for the column titles

</select><br>
    <label for="FO">Footrest Options: </label>
    <select name="FO">
    <option>----</option>
    <?
    foreach ($liftsecond as $lift){
echo '<option>'.$lift["Footrest Options"].'</option>';

}
?>
</select><br>


<label for="SW">Seat Width:  </label>
    <select name="SW">
    <option>----</option>
    <?
    foreach ($liftsecond as $lift){
echo '<option>'.$lift["Seat Width"].'</option>';

}
?>
</select><br>


<label for="SS">Seat Style:  </label>
    <select name="SS">
    <option>----</option>
    <?
    foreach ($liftsecond as $lift){
echo '<option>'.$lift["Seat Style"].'</option>';

}
?>
</select><br>

For instance, where I have:

<select name="FO">
<option>----</option>

Is there any way of querying my database to retrieve the column names and loop through them and create select boxes as necessary?

Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Simmondsp
  • 9
  • 3

1 Answers1

0

Query to get column name of table:

    <select name="FO">
    <option>----</option>
    <?php
         $sql = "SHOW COLUMNS FROM your-table";
            $result = mysqli_query($conn,$sql);
            while($row = mysqli_fetch_array($result)){
            echo "<option>".$row['Field']."</option>";
            } ?>
 </select>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Kumar Rakesh
  • 2,718
  • 2
  • 18
  • 39