0

我正在尝试使用此关联数组将关联数组中的项目显示到一个两列表中
foreach($this->inventory as $ID => $Info)

"<table width ='100%'>\n"; 
 foreach($this->inventory as $ID => $Info) {
    echo"<tr>";   
    echo"<td>".$Info['name'] <br>$Info['description']." </td>";
    echo"<td>".$Info['name'] <br>$Info['description']."</td>"; 
    echo"</tr>";
}
</table>

问题是它在每一行上显示每个项目两次。我希望它显示如下:

------------------------------------------------------------------
|Name: shoes                      |Name: bag
|Description: nike                |Description: swing bag
 -----------------------------------------------------------------
|Name: socks                      |Name: ear phones
|Description: black and white     |Description: beats
 -----------------------------------------------------------------
|Name: earrings                   |Name: phone
|Description: diamond  studs      |Description: blackberry  

但我得到了这个:

------------------------------------------------------------------
|Name: shoes                      | Name: shoes
|Description: nike                | Description: nike
 -----------------------------------------------------------------
|Name: bag                        | Name: bag 
|Description: swing bag           |Description: swing bag 
 -----------------------------------------------------------------
|Name: ear phones                 |Name: ear phones
|Description: beats               |Description: beats  
4

1 回答 1

1

我在这个小提琴http://jsfiddle.net/hnek2/中为这个伪表创建了 CSS

现在你可以使用这个 PHP:

echo('<div class="tbl">');
foreach($this->inventory as $ID => $Info) {
    echo('<div class="block">');   
    echo('<p>Name: ' . $Info['name'] . '</p><p>Description: ' . $Info['description'] . '</p>');
    echo('</div>');
}
echo('</div>');
于 2013-11-03T04:34:32.263 回答