简体   繁体   中英

how to display specific fields from db using the selected value in dropdown listbox in php

   <select id="qualification" class="form-control"> 
     <option selected="selected">SELECT</option> 
     <option value="pick"</option>
     <?php $sql = mysqli_query($con, "SELECT DISTINCT qualification From
     enquire"); 
      $row = mysqli_num_rows($sql); 
     while ($row = mysqli_fetch_array($sql))
     { echo "<option value='". $row['qualification'] ."'>".$row['qualification']."</option>" ; } ?>
    </select>

how to retrieve fields in table format from database using qualification ?

       <?php 
        $sql="SELECT Option1, option2 FROM yourTable";
        $result = mysqli_query($YourDBconnection,$sql);
      ?>

your SELECT like

<select>
<?php
while ($row = mysql_fetch_assoc($result)){
echo'<option>'.$row['option1'].'<option>';
}
?>
</select>

Do this

<select id="qualification" class="form-control"> 
     <option selected="selected">SELECT</option> 
     <option value="pick"</option>
     <?php $sql = mysqli_query($con, "SELECT DISTINCT qualification From
     enquire"); 
      //$row = mysqli_num_rows($sql); 
     while ($row = mysql_fetch_assoc($sql)))
     { ?>
<option value="<?php echo $row['qualification']; ?>"> <?php echo $row['qualification']; ?> </option> 
<?php } ?>
    </select>

You may wanna reconsider your codes and use prepared statement to avoid SQL injection. The below code is prepared statement

<select id="qualification" class="form-control"> 
     <option selected="selected">SELECT</option> 
     <option value="pick"</option>
     <?php $sql =$con->prepare("SELECT DISTINCT qualification From
     enquire");
      $sql->execute(); 
      $result = $sql->get_result(); 
     while ($row = $result->fetch_assoc())
     { ?>
<option value="<?php echo $row['qualification']; ?>"> <?php echo $row['qualification']; ?> </option> 
<?php } ?>
    </select>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM