How can the issue of multiple "ID not found" outputs be resolved when a user inputs an ID that does not exist in the database?

Issue: When a user inputs an ID that does not exist in the database, multiple "ID not found" outputs may be displayed, cluttering the user interface. To resolve this issue, we can add a condition to check if the query result is empty before displaying the "ID not found" message. PHP Code Snippet:

$id = $_POST['id']; // Assuming the ID is submitted via POST method

$query = "SELECT * FROM table_name WHERE id = $id";
$result = mysqli_query($connection, $query);

if(mysqli_num_rows($result) > 0) {
    // Display the data
} else {
    echo "ID not found";
}