开发者

Array and DESC LIMIT

Here's my problem:

$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) //开发者_如何学Python don't work
        $procent[] = 1;
    else
        $procent[] = $row[percent];
}
$procent[] = implode('-', $procent);


Try: if ($row["percent"] == null || $row["percent"] == "")


try

if ($row[percent] === null)

When using the non-strict == operator, 0 == null and '' == null will evaluate to true as well, which is probably not desirable.


$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);

and print:

12

4

66


Maybe if (! isset($row['percent'])) instead of if ($row['percent'] == null)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜