简体   繁体   English

如何检查$ row ['column_name']是否返回空的php mysql

[英]How to check if $row['column_name'] is returning empty php mysql

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?? 如何检查PHP?

Try this : 尝试这个 :

if(empty($row['describe'])) {
    //$row['describe'] is empty
} else {
    //$row['describe'] is not empty
}

Also please dont use mysql_* . 另外请不要使用mysql_* It's deprecated and removed from PHP 7. Use mysqli_* or PDO . 它已被弃用并从PHP 7中删除。使用mysqli_*PDO

This can help you. 这可以帮到你。 First check the query doesn't return empty then check the describe column is not empty. 首先检查查询不返回空,然后检查describe列是否为空。 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: 您可以使用==0 ,这将检查它是否等于0:

if ($row['describe']==0) { /* code to do */ }

Or empty() , this will check if it is empty: 或者为empty() ,这将检查它是否为空:

if (empty($row['describe'])) { /* code to do */ }

Personally, I would prefer !empty() as this will check if the variable is empty. 就个人而言,我更喜欢!empty()因为这将检查变量是否为空。

Hope this helps, thanks! 希望这有帮助,谢谢!

Use if condition like below 如果条件如下,请使用

if ($row['describe'] == ""){
     echo "Description is empty";
}else{
    echo $row['describe'];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM