将mysql值分配给多维数组

时间:2010-02-03 10:47:54

标签: php mysql arrays multidimensional-array

我正在尝试使用php nd mysql将多维数组显示到html表中。

数组结构如下

Array
(
    [az] => Array
        (
            [0] => Array
                (
                    [work] => dsdsds
                    [time] => 2:47---2:55
                    [total] => 8
                )

        )

    [an] => Array
        (
            [0] => Array
                (
                    [work] => sdsdsdsdsd
                    [time] => 1:47---2:47
                    [total] => 60
                )

        )

    [mu] => Array
        (
            [0] => Array
                (
                    [work] => sdsdsd
                    [time] => 1:30---2:48
                    [total] => 78
                )

        )

    [raj] => Array
        (
            [0] => Array
                (
                    [work] => dsdwew
                    [time] => 3:34---3:40
                    [total] => 6
                )

            [1] => Array
                (
                    [work] => cdsfdfdfd
                    [time] => 3:25---3:35
                    [total] => 10
                )

        )

)

它将首先遍历列,然后它将会出现像这样的行

user1   user2   user3
aa      bb      cc

Plz建议..

2 个答案:

答案 0 :(得分:1)

你应该读一读foreach。

http://php.net/manual/en/control-structures.foreach.php

我认为将这些值插入表中不会有任何问题。

答案 1 :(得分:0)

如果我理解你的问题,写下你需要的东西

    foreach($array as $tr=>$trData)
    {
      echo "<tr>{$trData["which field you want to display"]}</tr>";

      echo "<tr>";
      foreach($tdData as $td=>$tdData)
      {
         echo "<td>{$tdData["which field you want to display"]}</td>";
      }
    echo "</tr>";
    }