Reputation: 17
I just want an answer that can tell me about making a dropdown select list that contains the names of available databases of Mysql using php. I tried to figure it out but i am stucked as my following code is generating a dropdown list but for every database there is a seperate dropdown whereas i want to put all the names in a single dropdown. really not getting the way.
here is the code :
<?php
$sql="SHOW DATABASES";
$link = mysqli_connect('hostname', 'username', 'password') or die ('Error connecting to mysql: ' . mysqli_error($link).'\r\n');
$result=mysqli_query($link,$sql);
while( $rs=mysqli_fetch_array($result)){
echo "<select name='DB'>";
echo '<option value='.$rs[0].'>'.$rs[0].'</option>';
echo "</select>";
}
?>
any help would be appreciated.
Upvotes: 0
Views: 32
Reputation: 373
echo "<select name='DB'>";
while( $rs=mysqli_fetch_array($result)){
echo '<option value='.$rs[0].'>'.$rs[0].'</option>';
}
echo "</select>";
Enjoy )
Upvotes: 1