这是我的问题:
$q = 'SELECT * FROM s_stats WHERE srv_id='.$sid.' ORDER BY date DESC LIMIT 5';
$result = mysql_query($q) or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
if ($row[percent] == null) // don't work
$procent[] = 1;
else
$procent[] = $row[percent];
}
$procent[] = implode('-', $procent);
答案 0 :(得分:0)
可能if (! isset($row['percent']))
代替if ($row['percent'] == null)
答案 1 :(得分:0)
试
if ($row[percent] === null)
使用非严格==
运算符时,0 == null
和'' == null
也会评估为true,这可能是不可取的。
答案 2 :(得分:0)
尝试:if ($row["percent"] == null || $row["percent"] == "")
答案 3 :(得分:0)
$q = 'SELECT * FROM s_stats WHERE srv_id='.$sid.' ORDER BY date DESC LIMIT 5';
$result = mysql_query($q) or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
echo '*', $row['percent'], '*<br/>';
if (!isset($row["percent"]))
$procent[] = 1;
else
$procent[] = $row[percent];
}
$procent[] = implode('-', $procent);
并打印:
12
4
66