我编写了一个代码来获取所有用户的电子邮件,然后将其保存在txt文件中,但有些用户没有电子邮件,因为他们使用电话号码注册 所以当我试图去取 它转储在txt文件中 http://prntscr.com/5wf7cv
我希望如果单元格为空/ NULL则不提取任何内容 任何人都可以帮我修复它吗?
$sql=mysql_query("SELECT * FROM user ");
while($row = mysql_fetch_array($sql)) {
$email = $row['email'] ;
$fp = fopen("emaillist.txt", "a");
$savestring = "\n$email";
fwrite($fp, $savestring);
fclose($fp);
}
echo "DONE ";
答案 0 :(得分:0)
将查询更改为
SELECT * FROM user WHERE email != NULL
答案 1 :(得分:0)
试试这个:
$sql=mysql_query("SELECT * FROM user ");
while($row = mysql_fetch_array($sql)) {
if (strlen($row['email'] ) > 0){
$email = $row['email'];
$fp = fopen("emaillist.txt", "a");
$savestring = "\n$email";
fwrite($fp, $savestring);
fclose($fp);
}
}
echo "DONE ";
答案 2 :(得分:0)
SELECT * FROM user WHERE email IS NOT NULL
检查NULL值的唯一方法是
column IS NULL
或column IS NOT NULL