我已在 jpg 文件中附加了代码格式问题的问题:::
问题是它没有将任何数据保存到“tbl_featured_table”中。
控制器
public function save_featured_product() {
$data = array();
if ($this->input->post()) {
$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['featured_product_name'] = $this->input->post('featured_product_name', true);
$data['featured_product_price'] = $this->input->post('featured_product_price', true);
$data['featured_product_quantity'] = $this->input->post('featured_product_quantity', true);
$data['featured_product_sku'] = $this->input->post('featured_product_sku', true);
$data['featured_product_short_description'] = $this->input->post('featured_product_short_description', true);
$data['featured_product_long_description'] = $this->input->post('featured_product_long_description', true);
$data['featured_product_status'] = $this->input->post('featured_product_status', true);
$data['featured_product_image'] = $this->input->post('featured_product_image', true);
$this->sa_model->save_featured_product_info($data);
}
模型
function save_featured_product_info($data){
if (isset($data['product_id']) && is_array($data['product_id'])) {
foreach ($data['product_id'] as $key => $each) {
$temp[] = array(
'featured_id' => $data['featured_id'][$key],
'product_id' => $data['product_id'][$key],
'product_name' => $data['product_name'][$key],
'featured_product_name' => $data['featured_product_name'][$key],
'featured_product_price' => $data['featured_product_price'][$key],
'featured_product_quantity' => $data['featured_product_quantity'][$key],
'featured_product_sku' => $data['featured_product_sku'][$key],
'featured_product_short_description' => $data['featured_product_short_description'][$key],
'featured_product_long_description' => $data['featured_product_long_description'][$key],
'featured_product_status' => $data['featured_product_status'][$key],
'featured_product_image' => $data['featured_product_image'][$key],
);
}
if (isset($temp)) {
$this->db->insert_batch('tbl_featured_products', $temp);
}
看法
Product Name:
<select name="product_id[]">
<?php foreach ($all_product as $values) { ?>
<option value="<?php echo $values->product_name; ?>"><?php echo $values->product_name; ?></option>
<?php } ?>
</select>
<?php foreach ($all_product as $values) { ?>
<input type="checkbox" name="featured_product_name[]" value="<?php echo $values->product_name; ?>" />
<?php echo $values->product_name; ?> <br>
<input hidden="hidden" name="featured_id[]" value="<?php echo $values->product_id; ?>" />
<input type="hidden" name="product_name[]" value="<?php echo $values->product_name; ?>" >
<input name="featured_product_price[]" value="<?php echo $values->product_price;?>" />
<input name="featured_product_quantity[]" value="<?php echo $values->product_quantity; ?>" />
<input name="featured_product_sku[]" value="<?php echo $values->product_sku; ?>" />
<input name="featured_product_short_description[]" value="<?php echo $values->product_short_description; ?>" />
<input name="featured_product_long_description[]" value="<?php echo $values->product_long_description; ?>" />
<input name="featured_product_status[]" value="<?php echo $values->product_status; ?>" />
<input name="featured_product_image[]" value="<?php echo $values->product_image; ?>" />
<?php } ?>
注意 ::: 我想按产品名称或产品 ID 保存多个数据。它也不能正常工作。我需要你的帮助来解决我的问题。
请专业帮助我。请不要给我打负分。