Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 显示每个用户的数据_Php_Sql - Fatal编程技术网

Php 显示每个用户的数据

Php 显示每个用户的数据,php,sql,Php,Sql,我想显示每个用户的数据。 但它显示每个表和每个用户的所有数据。 因此,我试图实现的是为该用户显示表中的所有数据 这是我的密码 <?php foreach ($employee as $emp) { ?> <table id="employee-content"> <h3 class="color-orange"><?php echo $emp['members']['username']; ?></h3>

我想显示每个用户的数据。 但它显示每个表和每个用户的所有数据。 因此,我试图实现的是为该用户显示表中的所有数据 这是我的密码

<?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 } ?>'
还有打印的r$employee

* 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;
    }
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 ) )
输出是 示例屏幕截图

所以我想要实现的是 例如,用户“admin”的所有标题、说明、截止日期将显示在单个框或页面上。 其他用户也是如此


请提前帮忙谢谢

所以。。。看起来您的数据库结果当前的结构如下:

  • 结果1
    • 用户名1
    • 职位
  • 结果2
    • 用户名1
    • 职位
  • 结果3
    • 用户名2
等等,您希望您的显示器看起来像:

  • 用户名1
    • 职位
    • 职位
  • 用户名2
    • 职位
在我看来,实现您想要的最简单的方法是根据您选择的结果创建一个新数组

<?php

$posts_by_emp=array();
foreach ($employee as $emp) {
  $posts_by_emp[$emp['members']['username']][]=array(
    'title' => $emp['posts']['title'];
    'descr' => $emp['posts']['title'];
    'deadline' => $emp['posts']['deadline']
  );
}

$hfmt = "<tr>\n    <th colspan='3' class='color-orange'>%s</th>\n  </tr>";
$bfmt = "<tr>\n"
      . "    <td class='personal-management-content'>%s</td>\n"
      . "    <td class='personal-management-content padding-left50'>%s</td>\n"
      . "    <td class='personal-management-content padding-left50'>%s</td>\n"
      . "  </tr>";

print "  <table id='employee-content'>";
foreach ($posts_by_emp as $username => $items) {
  // Print header
  printf($hfmt, $username);
  foreach ($items as $item) {
    // Print post
    printf($bfmt, $item['title'], $item['descr'], $item['deadline']);
  }
}
print "</table>\n";

欢迎来到StackOverflow。你的问题是什么?请提供更多细节。@ghoti很抱歉,这篇文章已经编辑过了① 添加填充$employee数组的SQL。② 显示一个
print\r($employee)
以便我们知道您的数据实际上是什么样子。③ 修复你的HTML。示例代码启动多个表,在错误的位置嵌入一个
,但没有完成任何一个表。明显的结构错误妨碍了调试问题中未包含的代码。如果您提供足够的代码,让回答问题的人能够在他们自己的系统上重现您的问题,您将得到最好的回答。@ghoti,按您的要求。如果您仍然需要一些东西,请回复,谢谢,我们正在改进!但据我所知,您仍然存在一些严重的HTML结构问题,即使您的查询是正确的,这些问题也会破坏您的输出。我不知道您的问题是关于修复HTML还是修复SQL,但这两个问题都不是您如何标记问题的。你在问题上加了标签。这些技术中哪一项是你真正遇到问题的?正如你的问题所暗示的那样,所有这些问题,还是需要进一步澄清?