I have a table with columns
id,name,phone,describe
While fetching the values from this table i am using
$row=mysql_fetch_array($query)
Now i want to check whether
$row['describe']
is returning empty value. How to check in php??
The easiest way is to use mysql_num_rows(). $cnt = mysql_num_rows($Result); if ( 0===$cnt ) { echo 'no records'; } else { while( false!=( $row=mysql_fetch_array($Result)) ) { // ... } }
SELECT * FROM yourTableName WHERE yourSpecificColumnName IS NULL OR yourSpecificColumnName = ' '; The IS NULL constraint can be used whenever the column is empty and the symbol ( ' ') is used when there is empty value.
You can use the empty() function which will check to see if anything is there. The isset() checks for a null (boolean==false) on the field - which you can also use.
A field with a NULL value is a field with no value. If a field in a table is optional, it is possible to insert a new record or update a record without adding a value to this field. Then, the field will be saved with a NULL value. Note: A NULL value is different from a zero value or a field that contains spaces.
You can use ==0
, this will check if it equals to 0:
if ($row['describe']==0) { /* code to do */ }
Or empty()
, this will check if it is empty:
if (empty($row['describe'])) { /* code to do */ }
Personally, I would prefer !empty()
as this will check if the variable is empty.
Hope this helps, thanks!
Try this :
if(empty($row['describe'])) {
//$row['describe'] is empty
} else {
//$row['describe'] is not empty
}
Also please dont use mysql_*
. It's deprecated and removed from PHP 7. Use mysqli_*
or PDO
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With