我想显示每个用户的数据。但它显示每个表和每个用户的所有数据。所以我想要实现的是为该用户显示表上的所有数据这是我的代码
<?php foreach ($employee as $emp) { ?>
<table id="employee-content">
<h3 class="color-orange"><?php echo $emp['members']['username']; ?></h3>
<tr>
<td><p class="personal-management-content"><?php echo $emp['posts']['title']; ?></p></td>
<td><p class="personal-management-content padding-left50" class="padding-left50"><?php echo $emp['posts']['title']; ?></p></td>
<td><p class="personal-management-content padding-left50" class="padding-left50"><?php echo $emp['posts']['deadline']; ?></p></td>
</tr>
<?php } ?>'
这是 $employee 的 sql 查询
* on controller
public function employee_management() {
$posts = $this->Post->getPostByMember();
$this->set("employee", $posts);
}
* on model
public function getPostByMember() {
$post = "SELECT username, content, deadline, title FROM members INNER JOIN posts ON posts.member_id=members.id";
// debug($user);
$con = $this->getDataSource();
$get = $con->fetchAll($post);
// debug($get);
return $get;
}
和 print_r $employee
Array (
[0] => Array (
[members] => Array (
[username] => admin )
[posts] => Array (
[content] => asdsadsad
[deadline] => 2012-06-01
[title] => sad ) )
[1] => Array (
[members] => Array (
[username] => admin )
[posts] => Array (
[content] => asd
[deadline] => 2012-06-20
[title] => sad ) )
[2] => Array (
[members] => Array (
[username] => admin )
[posts] => Array (
[content] => dasdw2
[deadline] => 2012-06-19
[title] => sdas ) )
[3] => Array (
[members] => Array (
[username] => guest )
[posts] => Array (
[content] => s
[deadline] => 2012-06-08
[title] => wara ) )
输出是示例屏幕截图 http://i46.tinypic.com/209n56s.jpg
所以我想要实现的是例如用户“管理员”他的所有标题、描述、截止日期将显示在单个框或 . 其他用户也是如此。
请帮助提前谢谢