美好的一天,我正在努力解决这个问题 结果" 10"设置$ fod但是需要替换它以显示被调用的行的id,以便SQL WHERE可以在相关行中列出正确的数据。请参阅图片了解结果。
See Current Result and Desired Result
如你所见,我需要ROW ID 10来显示10个项目,而ROW ID 11来显示11个项目。请帮助我,如何调用这些行正确显示?
通话功能:
Controller.php这样
$data['order_list'] = $this->product->data_ordershalf();
$fod = 10;
$data['order_listfull'] = $this->product->data_ordersfull($fod);
的functions.php:
function data_ordershalf(){
$this->db->select('*');
$this->db->join('order_detail', 'order_detail.orderid=orders.id', 'left');
$this->db->join('customers', 'customers.id=orders.customerid', 'left');
$this->db->join('testshop_products', 'testshop_products.product_id=order_detail.productid', 'left');
$this->db->from('orders');
$this->db->group_by('orderid');
$rs = $this->db->get();
return $rs->result_array();
}
function data_ordersfull($fod){
$this->db->select('*');
$this->db->join('orders', 'orders.id=order_detail.orderid', 'left');
$this->db->join('testshop_products', 'testshop_products.product_id=order_detail.productid', 'left');
$this->db->from('order_detail');
$this->db->where('orderid',$fod);
$rs = $this->db->get();
return $rs->result_array();
View.php:
<?php if(!$order_list){ ?>
<tbody>
<tr>
<th colspan="7"><center>No orders placed</center></th>
</tr>
</tbody>
<?php } else { $sr = 1; ?>
<tbody>
<?php foreach( $order_list as $row) { ?>
<tr>
<th scope="row"><?php echo $row['id']; ?></th>
<td><?php echo $row['date']; ?></td>
<td><?php echo $row['name']; ?></td>
<td>
<table>
<?php foreach( $order_listfull as $row2) { ?>
<tr>
<th scope="row"><?php echo $row2['id']; ?></th>
<td><?php echo $row2['product_name']; ?></td>
<td><?php echo $row2['quantity']; ?></td>
<td></td>
<td><?php echo $row2['price']; ?></td>
</tr>
<?php } ?>
</table>
</td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['price']; ?></td>
</tr>
<?php } ?>
</tbody>
<?php } ?>
答案 0 :(得分:1)
您可以创建帮助程序并将其放入以下功能。
function data_ordersfull($fod){
$this->db->select('*');
$this->db->join('orders', 'orders.id=order_detail.orderid', 'left');
$this->db->join('testshop_products', 'testshop_products.product_id=order_detail.productid', 'left');
$this->db->from('order_detail');
$this->db->where('orderid',$fod);
$rs = $this->db->get();
return $rs->result_array();
}
==================== View.php ======================== ==============
<?php if(!$order_list){ ?>
<tbody>
<tr>
<th colspan="7"><center>No orders placed</center></th>
</tr>
</tbody>
<?php } else { $sr = 1; ?>
<tbody>
<?php foreach( $order_list as $row) {
$order_listfull=data_ordersfull($row['id']);
?>
<tr>
<th scope="row"><?php echo $row['id']; ?></th>
<td><?php echo $row['date']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><table>
<?php foreach( $order_listfull as $row2) { ?>
<tr>
<th scope="row"><?php echo $row2['id']; ?></th>
<td><?php echo $row2['product_name']; ?></td>
<td><?php echo $row2['quantity']; ?></td>
<td></td>
<td><?php echo $row2['price']; ?></td>
</tr>
<?php } ?></table></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['price']; ?></td>
</tr>
<?php } ?>
</tbody>
<?php } ?>
答案 1 :(得分:0)
function data_ordershalf(){
$this->db->select('*');
$this->db->from('orders');
$this->db->join('order_detail', 'order_detail.orderid=orders.id', 'left');
$this->db->join('customers', 'customers.id=orders.customerid', 'left');
$this->db->join('testshop_products', 'testshop_products.product_id=order_detail.productid', 'left');
$this->db->group_by('order_detail.orderid');
$rs = $this->db->get();
return $rs->result_array();
}
function data_ordersfull($fod){
$this->db->select('*');
$this->db->from('order_detail');
$this->db->join('orders', 'orders.id=order_detail.orderid', 'left');
$this->db->join('testshop_products', 'testshop_products.product_id=order_detail.productid', 'left');
$this->db->where('order_detail.orderid',$fod);
$rs = $this->db->get();
return $rs->result_array();