I have the following code where I can get the field names from a table in a select box. How can I display the contents of a field when it is selected. 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 '<select name="mySelect" id="mySelect">';
while ($i < mysqli_field_count($link)) {
$meta =
mysqli_fetch_field_direct($result, $i);
echo '<option>' . $meta->name . '</option>';
$i = $i + 1;
}
echo '</select>';
}
mysqli_close($link);
?>