0

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); 
?> 
2
Contributors
1
Reply
38
Views
2 Weeks
Discussion Span
Last Post by Dani
1

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>'; 
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.