如何在codeigniter中按升序或降序对购物车数据进行排序

时间:2019-02-14 12:13:19

标签: codeigniter-3

我想在$ this-> cart-> contents()的顶部显示最新的项目;以下是我的添加到购物车并显示购物车功能。其显示内容,但我想在顶部显示新插入的项目。

public function show_cart(){
    $output='';
    foreach ($this->cart->contents() as $items) {

        $output .='
            <tr>
                <td>'.$items['name'].'</td>
                <td><a href="javascript:void(0)" id="'.$items['rowid'].'"qty="'.$items['qty'].'" class="minus"></a> <span class="c_qunt qty" id="qty">'.$items['qty'].'</span> <a href="javascript:void(0)" id="'.$items['rowid'].'"qty="'.$items['qty'].'" class="plus"></a></td>
                <td>'.number_format($items['price']).'</td>
                <td>'.number_format($items['subtotal']).'</td>
                <td>
                    <span style="font-size:40px; color:red" id="'.$items['rowid'].'" class="remove"></span>
                </td>
            </tr>
        ';
    }
    return $output;
}



public function add_to_cart(){
   $data = array(
            'id' => $this->input->post('product_id'), 
            'name' => $this->input->post('product_name'), 
            'price' => $this->input->post('product_price'), 
            'qty' => $this->input->post('qty'), 
        );
        $this->cart->insert($data); 
        echo $this->show_cart();
   }

0 个答案:

没有答案