To output MySQL data in HTML, you will need to use a server-side scripting language such as PHP or ASP.NET to retrieve data from the MySQL database and generate the HTML output that is sent to the user’s web browser.
For example, in PHP, you can use the mysqli_query
function to execute a SQL query and retrieve the results, and then use the mysqli_fetch_assoc
function to iterate over the rows of the result set and create the HTML output. The following code demonstrates how to retrieve data from a MySQL table and generate an HTML table to display the results:
query("SELECT * FROM mytable");
// Check for errors
if (!$result) {
printf("Error: %s\n", $mysqli->error);
exit();
}
// Start the HTML table
echo " \n";
// Print the table headers
echo "";
$field_info = mysqli_fetch_field($result);
while ($field_info) {
printf("%s ", $field_info->name);
$field_info = mysqli_fetch_field($result);
}
echo " \n";
// Print the table rows
while ($row = $result->fetch_assoc()) {
echo "";
foreach ($row as $col_value) {
printf("%s ", $col_value);
}
echo " \n";
}
// End the HTML table
echo "
\n";
// Free the result set
$result->free();
// Close the database connection
$mysqli->close();
?>
For more information and examples of how to output MySQL data in HTML using PHP, please refer to the PHP documentation and tutorials.