0

hello,

<?php

$q=$_GET['q'];

//echo $q;

$con=mysqli_connect("localhost","root","",$q);
    if (mysqli_connect_errno()) 
        {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}


$abc=mysqli_query($con,"use $q") or die('cannot show tables');

$result=mysqli_query($con,"show tables");
echo "<select id='abc'>";
        while($row= mysqli_fetch_array($result))
                {
echo "<option value='". $row[0]. "'/>" . $row[0] . "</option>";

                   }
                   echo "</select>";

?>

i want to response out only option values from this php file which is called upon by ajax.how can i do this....

??

Edited by pritaeas: Removed password.

3
Contributors
2
Replies
16
Views
3 Years
Discussion Span
Last Post by diafol
0

Hi there, try this:

HTML PAGE: jsFiddle

PHP:

<?php
// Connect to DB

$result = mysqli_query($con,"show tables");

while( $row = mysqli_fetch_array($result) )
{   
    echo "<option value='". $row[0]. "'>" . $row[0] . "</option>";
}
?>

Note: Your <option> tag was being closed in the opener, and there are a few minor errors in your code, but for the purpose of helping I've stuck with yours.

0

Just like to add - if you're only after number index items, use the second parameter and state MYSQLI_NUM, else you're retrieving both numbered index and associatives (default = MYSQLI_BOTH).

while( $row = mysqli_fetch_array($result, MYSQLI_NUM) )
{   
    echo "<option value='". $row[0]. "'>" . $row[0] . "</option>";
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.