将会话购物车存储到数据库



很抱歉问这些老问题,我知道我在问这里之前已经读过了,它可以使用数据库添加更多的购物车,没有限制。我已经尝试使用ci_sessions表来存储会话,但仍然没有成功,我最多只能添加6个项目。

请帮帮我,我在找这个例子将近两天了,结果什么都不是

已编辑这是我的观点

<table id="box-table-a" summary="Employee Pay Sheet">
        <thead>
            <tr>
                <th scope="col">Description</th>
                <th scope="col">Price</th>
                <th class="centered" scope="col">Options</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($foto_produk->result() as $key => $value) {?>
            <tr>
                <td><?php echo $value->description;?></td>
                <td><?php echo $value->price;?></td>
                <td class="centered"><input type="checkbox" name="produk_foto[]" value="<?php echo $value->id;?>" /></td>
            </tr>
            <?php }?>
        </tbody>
    </table>

这是我的控制器代码

if($this->input->post('produk_foto')){
       $id_foto = $this->input->post('produk_foto');
       foreach ($id_foto as $key => $value) {
           $this->db->where('id', $value);
           $query = $this->db->get('foto_product');
           if($query->num_rows() > 0){
               foreach($query->result() as $ids => $rows){              
                   echo $rows->id.'<br />';
                   $data_produk = array(
                       'user_data'=> array(
                            'id' => $rows->id, 
                            'price' => $rows->price,
                            'name' => $rows->description,
                            'qty' => $rows->aantal
                        )
                   );
                   $this->cart->insert($data_produk);
               }            
           }
       }
    }

这是我的视图代码

<?php if(!$this->cart->contents()):?>
    <div class="alert-box warning">The regular products are empty.</div>
    <div class="clearfix"></div>
    <?php else:?>
    <hr>
    <h4>REGULAR PRODUCTS</h4>
    <div class="order_detail" id="Display">
        <table>
            <thead>
                <tr>
                    <th>DESCRIPTION</th>
                    <th>QUANTITY</th>
                    <th>PRICE PER ITEM(S)</th>
                    <th>TOTAL</th>
                    <th>REMOVE</th>
                </tr>
            </thead>
            <tbody>
                 <?php foreach($this->cart->contents() as $rows):?>
                <tr>
                    <td style="font-weight:bold;"><?php echo $rows['name'];?></td>
                    <td>
                        <?php echo form_open(current_url());?>
                        <input type="text" size="3" name="quantity" value="<?php echo $rows['qty'];?>" />
                        <input type="hidden" size="3" name="rowid" value="<?php echo $rows['rowid'];?>" />
                        <input type="submit" name="update" value="Update" />
                        <?php echo form_close();?>
                    </td>
                    <td><?php echo $rows['price'];?></td>
                    <td><?php echo $this->cart->format_number($rows['subtotal']);?></td>
                    <td><a href="<?php echo base_url('index.php/en/payment/delete_item_product/'.$rows['rowid'].'');?>">delete</a></td>
                </tr>
                <?php endforeach;?>
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="3">Total Products</td>
                    <td colspan="3">&euro; <?php echo $this->cart->format_number($this->cart->total());?></td>
                </tr>
                <tr>
                    <td colspan="3">Total Shipping</td>
                    <td colspan="3"></td>
                </tr>
                <tr>
                    <td colspan="3"></td>
                    <td colspan="3" style="padding:0;text-align:center;">
                        <p>TOTAL :</p>
                        <span class="tot">&euro; <?php echo $this->cart->format_number($this->cart->total());?></span>
                    </td>
                </tr>
            </tfoot>
        </table>
    </div>
    <?php endif;?>

有了这段代码,我想用带数组的复选框插入,我有6个以上的复选框

提前感谢

好的,我自己解决了。。

我不知道产品名称中有特殊的字符。。

和我的耻辱。

但无论如何都要感谢

最新更新