让我解释一下我想要做什么。
在一个DBcommand.php文件中,我有:
class DBcommand Extends PdoDB {
public function selectAll() {
$stmt = $this->dbh->prepare("SELECT hwid,username,pcname FROM users");
$stmt->execute();
$columnn = array();
$result_returned = $stmt->fetchAll(PDO::FETCH_CLASS);
foreach($result_returned as $key=>$result) {
$columnn['hwid'] = $result->hwid;
$columnn['username'] = $result->username;
$columnn['pcname'] = $result->pcname;
//return $columnn;
//$columnn= new us($result->hwid,$result->username,$result->pcname);
}
return $columnn;
}
}
我正试图在另一个名为View.php的页面上获得我的结果
$cmd = new DBcommand();
//$get = $cmd->getInfo('1234');
$result=$cmd->selectAll();
echo '<tr ><td ><input type="checkbox" class="checkthis" /></td><td>' . $result['hwid'] . '</td><td style="cursor:pointer;" onclick="alert(\'ok\')">' . $result['username'] . '</td><td style="cursor:pointer;" onclick="alert(\'ok\')">' . $result['pcname']. '</td><td><p data-placement="top" data-toggle="tooltip" title="Edit"><button class="btn btn-primary btn-xs" data-title="Edit" data-toggle="modal" data-target="#edit" ><span class="glyphicon glyphicon-download-alt" onclick="myAjax()"></span></button></p></td>
<td><p data-placement="top" data-toggle="tooltip" title="Delete"><button class="btn btn-danger btn-xs" data-title="Delete" data-toggle="modal" data-target="#delete" ><span class="glyphicon glyphicon-trash"></span></button></p></td>
</tr>';
?>
我遇到的问题是,我的 selectall 有效,但我的 view.php 只能从中获取 1 个信息,无论是第一个还是最后一个。
即使我尝试在 view.php 部分做一些事情,它也永远不会得到所有结果。
假设我的 selectAll 返回数组('123','azerty',azerty');和数组('6547','qwertty',qwerty'); ,来自 selectAll 的print_r将显示我想看到的内容,但来自 view.php 的结果只会显示这两个结果之一。
--
我什至尝试创建另一个使用 $this->_hwid 的类,所以我稍后会使用这个类,但没有管理,因为它的对象是字符串结果。
--
卡住了,谢谢你的帮助。