Shivkesh Dwivedi Shivkesh Dwivedi - 1 month ago 6
MySQL Question

PHP - Get dropdwon list of available databases names.

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.

Answer
echo "<select name='DB'>";
while( $rs=mysqli_fetch_array($result)){

echo '<option value='.$rs[0].'>'.$rs[0].'</option>';

}
echo "</select>";

Enjoy )

Comments