2013-07-22 4 views
0

연관 배열이 PHP (id, orderType, details)에 지정된 순서대로 있습니다.PHP를 사용하여 동적으로 HTML 테이블에 데이터로드

내가 런타임에 HTML 테이블에서이 정보를 표시 할

[동안 페이지 로딩]

이 어떻게 달성하기 위해? 전에 이런 일은 한번도 한 적이 없으니 제발 저를 안내하십시오. 감사!

+0

2 루프 – Rufinus

+0

아약스 전화를 할 ... –

답변

0
echo '<table>'; 
foreach($yourarray as $row){ 
    echo '<tr>'; 
    foreach($row as $key=>$cell){ 
     echo '<td>'.$cell.'</td>'; 
    } 
    echo '</tr>'; 
} 
echo '</table>': 
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> 
및 에코
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>'; 
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>"; 
관련 문제