我希望你做得好。我是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>
答案 0 :(得分: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;
}
}
?>