Home > Backend Development > PHP Tutorial > 如何判断数据库里字段是否为空

如何判断数据库里字段是否为空

WBOY
Release: 2016-06-13 11:58:03
Original
3266 people have browsed it

怎么判断数据库里字段是否为空?
$query = mysql_query("select * from our where content is null");  这句对吗?
假如.我要判断字段为空就执行某些操作.不为空又执行另一操作..

$query = mysql_query("select * from our where content is null");<br /><br />    while($row = mysql_fetch_array($query)){<br />      $str = $row['content'];<br />    }<br /><br />    if($str){<br />      echo "1";<br />    }else{<br />      echo "2";<br />    }
Copy after login


我数据库里明明有字段..
为什么输出"2"

这是我的数据库字段.有2条.

------解决方案--------------------
我觉得是你的逻辑问题。当执行到if的时候,上面的while循环已经执行完了,而且游标已经指向最后一条记录的后面,也就是当前游标指向空,当然就没有值了。如果你把if语句放到while内部就不存在这个问题了。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template