-4
我正尝试在我的用户配置文件中创建一个在线/离线栏。它似乎不能100%工作,因为它总是在线显示。我使用下面的脚本吧:rowCount()返回不正确的行数
<?php
$user = $req_user_info['username'];
$sql = $db->query("SELECT COUNT(*) FROM blog_active_users
WHERE `username` = {$user}");
$num_rows = $sql->rowCount();
if (!$sql || ($num_rows < 0)) {
echo '<div class="span2 alert alert-error"><h4>offline</h4></div>';
} else if ($num_rows > 0) {
echo '<div class="span2 alert alert-success"><h4>online </h4></div>';
}
?>
我已经尝试过的脚本num_rows > 0
和== 0
但似乎没有任何工作。 我也试图在第一个num_row > 0
,然后num_row < 0
,但没有奏效。
也为以下人的答案。这是我的答案脚本:
<?php
$user = $req_user_info['username'];
$sql = $db->query("SELECT * FROM blog_active_users WHERE `username` = '".$req_user_info['username']."'");
$num_rows = $sql->rowCount();
if(!$sql || ($num_rows == 0)){
echo '<div class="span2 alert alert-error"><h4>offline</h4></div>';
}else{
echo '<div class="span2 alert alert-success"><h4>online </h4></div>';
}
?>
尽量想什么* *您选择。 –
使用'COUNT(*)'和'rowCount()'没有意义。 – samayo