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....

??

Recommended Answers

All 2 Replies

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.

Member Avatar for diafol

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>";
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.