PHP: Catch empty MySQL result
Question by Guest | 2012-11-22 at 17:20
In one of my PHP scripts, it may happen that the result of a MySQL query is empty.
Silly, if then the script just keeps running. Therefore, I would like to know - before outputting the data - if my MySQL result delivers an empty set or data is available. How can I implement it?
Related Topics
MySQL: Line Breaks in MySQL
Tip | 0 Comments
PHP: Remove all empty elements from string array
Tip | 0 Comments
HTML5 Validator: How to fix "Warning trimming empty <p> or <div>"
Question | 1 Answer
MySQL: CSV Export as automatic Download
Tutorial | 0 Comments
MySQL: Change minimum word length for full text search
Tip | 1 Comment
JavaScript: Catch Submit of Form
Tutorial | 0 Comments
jQuery: Submit complete form and receive content with Ajax
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
You can simply use the function mysqli_num_rows(). This function returns the number of records (rows) containing your result:
$res = mysqli_query($db, "SELECT * FROM tab WHERE id > 80"); if (mysqli_num_rows($res) == 0) { echo 'There were no matches.'; } else { // output data }In this way, you can design your code, to show the user, if there were no hits.
Last update on 2020-09-15 | Created on 2012-11-24