PHP MySQL选择问题

PHP MySQL选择问题,php,mysql,database,reporting,Php,Mysql,Database,Reporting,我有一个名为Emplyes的数据库,其结构如下: id name entrydate totalhours 1 test 11/11/2015 8 2 test2 11/11/2015 7 3 test 11/12/2015 8 4 test2 11/12/2015 9 我想把它交给像这样的人 id name 11/11/2015 11/12/2015 1 test 8 8 2 test2

我有一个名为Emplyes的数据库,其结构如下:

id name   entrydate    totalhours
1  test   11/11/2015      8
2  test2  11/11/2015      7
3  test   11/12/2015      8
4  test2  11/12/2015      9
我想把它交给像这样的人

id name 11/11/2015  11/12/2015 
1  test      8          8
2  test2     7          9
我尝试了几种方法,但没有结果我怎么能做到这一点?
提前谢谢

一旦你确定了日期,像这样的东西应该可以在PHP中使用

<?php

require('path/to/connection/stateme.nts');

$query = "
SELECT name
     , entrydate
     , totalhours
  FROM my_table
 ORDER
    BY name;
";

$result = mysqli_query($db,$query);

$array = array();

while($row = mysqli_fetch_assoc($result)){
$array[] = $row;
}


foreach ($array as $element)
    $newArray[$element["name"]][] = array($element["entrydate"]=>$element["totalhours"]);

print_r($newArray);

?>

…可以很容易地输出到表或json

我想在3周后看到您的表结构它将包含大量数据标准是什么?@草莓听到这个消息我很震惊。我相信OP想要一份月度报告,日期显示在列中,而不是行中。这就是所谓的数据透视或交叉列表查询。我链接的主题提供了这个问题的解决方案。显然,该解决方案必须针对这一特定问题进行定制。阅读pivot表,如:我尝试过但没有成功:|
Array
(
    [test] => Array
        (
            [0] => Array
                (
                    [2015-11-11] => 8
                )

            [1] => Array
                (
                    [2015-11-12] => 8
                )

        )

    [test2] => Array
        (
            [0] => Array
                (
                    [2015-11-11] => 7
                )

            [1] => Array
                (
                    [2015-11-12] => 9
                )

        )

)