Member Avatar for Tan_2

Hi! I need help with the following code. This code gives the results in a single row. I need it to be displayed in a selectbox. I need expert help with this. please. thanks.

<?php 

$host = 'localhost'; 
$port = '3306'; 
$server = $host . ':' . $port; 
$user = 'root'; 
$password = ''; 
$link = count($t_tmp = explode(':', $server)) > 1 ? mysqli_connect($t_tmp[0], $user, $password, '', $t_tmp[1]) : mysqli_connect($server, $user, $password); 
if (!$link) { 
    die('Error: Could not connect: ' . mysqli_error($link)); 
} 
$database = 'mydb'; 
mysqli_select_db($link, $database); 
$query = 'select * from mytable'; 
$result = mysqli_query($link, $query); 
if (!$result) { 
    $message = 'ERROR:' . mysqli_error($link); 
    return $message; 
} else { 
    $i = 0; 
    echo '<html><body><table><tr>'; 
    while ($i < mysqli_field_count($link)) { 
        $meta =  
        mysqli_fetch_field_direct($result, $i); 
        echo '<td>' . $meta->name . '</td>'; 
        $i = $i + 1; 
    } 
    echo '</tr>'; 
    echo '</table></body></html>'; 
    mysqli_free_result($result); 
} 
mysqli_close($link); 
?> 

This code connects to a database. Do you mean just replacing the table with a dropdown?

echo '<html><body><select>'; 
while ($i < mysqli_field_count($link)) { 
    $meta =  
    mysqli_fetch_field_direct($result, $i); 
    echo '<option>' . $meta->name . '</option>'; 
    $i = $i + 1; 
} 
echo '</select></html>'; 
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.