使用php动态加载html表中的数据

时间:2013-07-22 10:37:19

标签: php html-table

我在php中有关联数组(id,orderType,details),与指定的顺序一样。

我想在运行时 html表中显示此详细信息 [加载页面时]

如何实现这一目标?我之前从未做过这样的事,所以请指导我。谢谢!

4 个答案:

答案 0 :(得分:0)

echo '<table>';
foreach($yourarray as $row){
    echo '<tr>';
    foreach($row as $key=>$cell){
        echo '<td>'.$cell.'</td>';
    }
    echo '</tr>';
}
echo '</table>':

答案 1 :(得分:0)

<table>
<tr>
    <td>Id</td>
    <td>Order</td>
    <td>Type</td>
    <td>Details</td>        
</tr>
<?php
$your_array = array( array('id' => 12, 'order'=>1233, 'type'=> 1233, 'details'=>2444),
 array('id' => 1, 'order'=>14, 'type'=> 444, 'details'=>88));
    foreach($your_array as $row){ ?>
    <tr>
      <td><?php echo $row['id']; ?></td>
      <td><?php echo $row['order']; ?></td>
      <td><?php echo $row['type']; ?></td>
      <td><?php echo $row['details']; ?></td>
    </tr>       
<?php } ?>
</table>

答案 2 :(得分:0)

//detail() is your assosicative array

echo '<table><tr>';
echo '<td>id</td><td>orderType</td><td>details</td>';
echo '</tr>';

foreach($detail as $row){
    echo '<tr>';
    echo '<td>'.$row['id'].'</td>';
    echo '<td>'.$row['orderType'].'</td>';
    echo '<td>'.$row['details'].'</td>';
    echo '</tr>';    
}

echo '</table>';

答案 3 :(得分:0)

$headerFlag = false;
$result = "<table border='2'>";
foreach ($array as $row){
     $result = $result."<tr>";
     if($headerFlag == false){
            foreach($row as $key => $cell){  
                 $result = $result."<th>".$key."</th>";
            }
            $headerFlag = true;
            $result = $result."</tr>";
      }
      foreach($row as $key => $cell){
            $result = $result."<td>".$cell."</td>";
      }
      $result = $result."</tr>";
}
echo $result = $result."</table>";