我想根据其包显示对象(item)。使用我现在的PHP代码,我得到了这样的结果:
----------------------------------------------------------------------
Package Price Deskription Prodcut
----------------------------------------------------------------------
=> 2kg 20 sdasdsada
=> 4kg 40 sdasdsada PRODCUT ONE
=> 6kg 60 sdasdsada
=> 8kg 80 sdasdsada
----------------------------------------------------------------------
=> 2kg 20 sdasdsada
=> 4kg 40 sdasdsada PRODCUT TWO
=> 6kg 60 sdasdsada
=> 8kg 80 sdasdsada
=>
是一个下拉列表
然而,我想要的结果是这样的:
----------------------------------------------------------------------
Package Price Deskription Etc
----------------------------------------------------------------------
20 sdasdsada
=> 2,4,6,8kg 40 sdasdsada PRODCUT ONE
60 sdasdsada
80 sdasdsada
----------------------------------------------------------------------
20 sdasdsada
=> 2,4,6,8kg 40 sdasdsada PRODCUT TWO
60 sdasdsada
80 sdasdsada
请帮助
<?php
include ("config.php");
$results = $mysqli->query
("
SELECT product_package.id,
product_package.size,
product_package.price,
product_package.description,
product_package.image,
product_list.code,
product_list.name
FROM product_package
LEFT JOIN product_list ON product_list.code = product_package.code"
);
$orders = array();
$html = '';
if ($results) {
while($obj = $results->fetch_object()) {
$orders[$obj->code][$obj->size] = array(
'code' => $obj->code,
'size' => $obj->size,
'name' => $obj->name,
'price' => $obj->price,
'description' => $obj->description,
'image' => $obj->image);
}
$html .= '<table width="100%" id="orderHistoryTable"><div>';
$html .= '<td>package_size</td>';
$html .= '<td>price</td>';
$html .= '<td>description</td>';
$html .= '<td>image</td>';
$html .= '<td>name</td>';
foreach ($orders AS $order_id => $order) {
$orderCount = count($order);
$html .= '<tbody id="ttbody">';
$row = 1;
foreach ($order AS $item => $data) {
if ($row > 1) { $html .= '</tr><tr>'; }
$html .= '<td>';
//HELP ME HERE
$html .= '<select>';
$html .= '<option>'.$data['size'].'</option>';
$html .= '</select>';
//HELP ME HERE
$html .= '</td>';
$html .= '<td>' . $data['price'] . '</td>';
$html .= '<td>'. $data['description'] . '</td>';
$html .= '<td>' . $data['image'] . '</td>';
if ($row == 1)
$html .= '<td rowspan="' . $orderCount . '">' . $data['name'] . '</td>';
$row++;
}
}
$html .= '</div>';
$html .= '<tbody>';
$html .= '</table>';
}
echo $html;
?>