What is the common issue when trying to output data from a database in PHP and receiving a "Resource id" message?
When trying to output data from a database in PHP and receiving a "Resource id" message, it means that the data is not being fetched properly from the database. This issue commonly occurs when attempting to directly output the result resource from a database query without fetching the actual data. To solve this problem, you need to fetch the data from the result resource using functions like `mysqli_fetch_assoc`, `mysqli_fetch_array`, or `mysqli_fetch_row`.
// Connect to the database
$connection = mysqli_connect("localhost", "username", "password", "database");
// Perform a query
$query = "SELECT * FROM table";
$result = mysqli_query($connection, $query);
// Fetch and output the data
while ($row = mysqli_fetch_assoc($result)) {
echo $row['column_name'] . "<br>";
}
// Close the connection
mysqli_close($connection);