0

我希望你做得很好。我是codeigniter的新手:::

我在数据库 1. tbl_product 2. tbl_featured_products 中有两个表。我以复选框系统中带有 foreach 循环的形式从 tbl_product 获取数据。之后我需要将产品数据保存到 tbl_featured_products 中。我无法保存它(行中有多个数据)..请帮帮我..

我的问题:: 1. 如何将数据保存到 tbl_featured_products 中?2.如何显示图像和其他信息并从视图页面保存数据?

控制器:::

    $data=array();

    $data['featured_id']=$this->input->post('featured_id',true);
    $data['product_id']=$this->input->post('product_id',true);
    $data['product_name']=$this->input->post('product_name',true);
    $data['product_price']=$this->input->post('product_price',true);
    $data['product_image']=$this->input->post('product_image',true);

    $this->sa_model->save_featured_product_info($data);
} 

模型 :::::

public function save_featured_product_info($data)
{
    $this->db->insert('tbl_featured_products',$data);
}

看法::::

    <tr>
        <td width="130">Product Name: </td>

        <td>

            <?php foreach($all_product as $values) { ?>
                <input type="checkbox" name="product_name" value="<?php echo $values->product_name;?>"> <?php echo $values->product_name;?> <br>

            <?php } ?>

        </td>
    </tr>
4

1 回答 1

0

我会尝试以下操作:首先将数据加载到您的视图中

控制器:

function dataToView(){
   $data = $this->sa_model->tbl_product_info($data); //gets information from your model db 
   $this->load->view('templates/home', $data); //sends data to the view
}

看法:

<tr>
    <td width="130">Product Name: </td>

    <td>
        <form id="product_form">
        <?php foreach($all_product as $values) { ?>
            <input type="checkbox" name="product_name" value="<?php echo $values->product_name;?>"> <?php echo $values->product_name;?> <br>
        <?php } ?>
            <input type="submit" />
        </form>
    </td>
</tr>

Javascript

<script>
    $(document).ready(function(){
        $('#product_form').submit(function(){
            var url = 'controller/save';
            $.post(url, function(result){
                if (result){
                    //...your success function..
                }
            });
            return false;
        });
    });

</script>

控制器

<?php
function save(){
    $product = $this->input->post('product_name');//this will get your posted product into the controller
    //...add your own function
    if (works){
        echo true;
    }else{
        echo false;
    }

}
?>
于 2013-09-16T14:12:10.433 回答