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??
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
.
This can help you. First check the query doesn't return empty then check the describe
column is not empty. Only then go for performing action(s).
if ((mysql_num_rows($result) !=0 ) && (!empty($row['describe']) )
{ //PERFORM ACTION }
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!
Use if condition like below
if ($row['describe'] == ""){
echo "Description is empty";
}else{
echo $row['describe'];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.