return true if the db found records in php

To check if the database has found any records in PHP, you'll need to perform a query on the database and then check if any rows were returned.

Here's an example:

main.php
// perform a query that might return some results
$query = "SELECT * FROM my_table WHERE some_condition = 'true'";
$result = mysqli_query($connection, $query);

// check if any rows were returned
if (mysqli_num_rows($result) > 0) {
    // the database found records
    return true;
} else {
    // no records were found
    return false;
}
341 chars
13 lines

In this example, we're using the mysqli_query function to perform a SELECT statement on the my_table table in the database. We then use the mysqli_num_rows function to get the number of rows returned by the query.

If mysqli_num_rows returns a number greater than 0, then the database found records that match the condition in the SELECT statement. We can return true to indicate that the query was successful.

If mysqli_num_rows returns 0, then no records were found that match the condition. We can return false to indicate that the query was not successful.

gistlibby LogSnag