我正在尝试在mydatabase中获得在线用户列表:
public function get_list() {
try {
$query = $this->cn->prepare("select username from user where connect = 1");
$query->execute();
$result = $query->fetchAll();
return $result;
}catch(PDOException $ex) {
echo $ex->getMessage();
}
,然后在controller:
中打印结果$participation = new participation();
$list = new model_participation();
$participation->list_user_online($list->get_list());
视图的页面是这样的:
public function list_user_online($list_user){
echo "<div id='content'>
<div id='list_user_online'><h2>list_user_online</h2>";
foreach ($list_user as $data) {
echo "<tr><td>$data[0]</td></tr>";
}
echo "</div>";
}
的问题,其中显示的结果如下:user1user2user3实际上,我想这样打印它:user1user2user3
请帮帮我,谢谢你。
像这样修改代码:
public function list_user_online($list_user){
echo "<div id='content'>
<div id='list_user_online'><h2>list_user_online</h2>";
echo "<table><tr>";
foreach ($list_user as $data) {
echo "<td>$data[0]</td>";
}
echo "</tr></table>";
echo "</div>";
}
或使用CSS样式你的div-s:-)
use echo "<tr><td>$data[0] </td></tr>";