empty()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

empty()

Post by Jim_Bo »

Hi,

Should this work?

Doesnt seem to echo the result if the query is empty

Code: Select all

if (empty($result)) {
?


Thanks
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

See the manual...;)

empty() will return true if the value is one of:
NULL
0
'' (empty string)
false (boolean)
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

mysql_query() will only return FALSE if there is an error.

If there are no rows returned, it will still return a result set, it'll just have no rows in it.

To check the number of rows returned in a result, use:

Code: Select all

<?php

$result = mysql_query($query);

if (mysql_num_rows($result) < 1) {

    die('No rows returned!');

}

?>
or similar.
Post Reply