0

How to select all table names from a database and show them in select option(or dropdown list) using php and msqli.

 $db_selected = mysqli_select_db($data,$sub); 
 if(!$db_selected) 
  { 
      die ("Can\'t use : ".$sub . mysqli_error($data));
  } 
  $result =  mysqli_query( $data,"show tables"); ?>
  <form action="checkanswers.php" method="post">
<select class="form-select" aria-label="Default select example" 
 name="sell">
 <option selected>Please select a subject.</option>
 <?php 
    while($row = mysqli_fetch_assoc($result)) { 
     $table=$row[$sub];
  ?>
 <option>
<?php echo "$table" ?> </option>
 <?php }?>
</select>
<button type="submit" class="btn btn-primary" title="Check 
Answer">Check Answer</button>
</form>
Dharman
  • 30,962
  • 25
  • 85
  • 135
kretosian
  • 9
  • 3
  • Exactly how you are doing it except for this little thing `$sub`. What is this supposed to be? – Dharman Jan 15 '22 at 20:13
  • if you saw $db_selected = mysqli_select_db($data,$sub); then you know that i'm trying to select a database which is $sub and I want to show all the table name of $sub (DB) in select option of form . – kretosian Jan 17 '22 at 07:07
  • Ohh ok. Unfortunately, MySQL is stupid and it prefixes the name. – Dharman Jan 17 '22 at 08:05

0 Answers0