【发布时间】:2016-08-26 14:55:21
【问题描述】:
我使用 PHP - OOP - PDO 制作用户在线页面
include_once '../database.php'; $db = 新数据库();
$getRows = $db->getRows('select * from visitors_online');
$gr = $db->rowCount();
$online = '';
$getRow = $db->getRow('select * from user_online');
$gr2 = $db->rowCount();
if(!empty($gr2)) {
try {
while ($getR = $getRow){
$getRow = $db->getRow('select * from users where id = ?',[$getR['session']]);
echo ',   <a href="dashboard.php?user='.$getRow['username'].'">'.$getRow['username'].'</a>   ';
}
} catch (PDOException $e) {
die('Error :'. $e->getMessage());
}
$total = $gr + $gr2;
问题是: * 不显示除管理员以外的任何用户,我也得到了这个:
ONLINE
管理员
注意:未定义索引:第 56 行 /Applications/MAMP/htdocs/baws/admin/online.php 中的会话
,
.Users = 0 ,Member = 2 , Register = 2
谁在线列表
这是来自数据库类的函数
// Get row by id, username, or email etc..
public function getRow($query, $para = []){
try {
$this->stmt = $this->datab->prepare($query);
$this->stmt->execute($para);
return $this->stmt->fetch();
} catch (PDOException $e) {
throw new Exception($e->getMessage());
}
}
任何帮助
谢谢
【问题讨论】:
-
您将 $para 作为空数组传递。不会工作。或者简单地执行();
-
我从类中传递了我需要的东西 $getRow = $db->getRow('select * from users where id = ?',[$getR['session']]);。 .... 所以你怎么看?如何解决它
-
我敢打赌这不是你的完整代码。您发布的内容缺少大括号。
-
这是我第二次在这里添加帖子,我在这里添加代码时遇到问题我不知道那是不是来自我的笔记本电脑