我想在投票時選擇它時,增加數據庫中選項的值。我沒有收到任何錯誤,但數據庫沒有更新。我究竟做錯了什麼?在數據庫codeigniter中遞增值
在我的控制器:
public function vote($option_id)
{
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_rules('options', 'required');
if ($this->form_validation->run() === FALSE)
{
$this->load->helper('html');
$data['content'] = $this->load->view('user/vote','', TRUE);
$this->load->view('templates/master', $data);
}
else{
$checkedoption = intval($_POST['options']);
$optionid = $this->polls_model->get_option($option_id);
$this->polls_model->set_votes($checkedoption, $option_id);
$this->load->helper('html');
$data['content'] = $this->load->view('user/success','', TRUE);
$this->load->view('templates/master', $data);
}
}
在我的模型,我擁有的功能是這樣的:
//this gets the id of the option to vote on
function get_option($option_id)
{
$query = $this->db->get_where('pollOption', array('option_id'=>$option_id));
return $query->row_array();
}
// THis updates the vount_count column in the database:
public function set_votes($checkedoption, $option_id)
{
$this->db->where('option_id', $checkedoption);
$this->db->set('vote_count', 'vote_count+1', FALSE);
$this->db->update('pollOption');
}
,並在我看來,我有這樣的:
$poll_id = $polls_item['id'];
$query = $this->db->get_where('pollOption', array('poll_id' => $poll_id));
$queryResult = $query->result_array();?>
<html>
<head>
<script type="text/javascript" src="<?php echo base_url();?>js/jquery.js"></script>
</head>
<body>
<?php echo form_open('user/vote/' .$poll_id);
foreach ($queryResult as $row):?>
<input type="radio" name="options" value = "<?php echo $row['option_item'];?>" > <?php echo $row['option_item'];?> <br>
<?php endforeach;?>
<input type="submit" name="submit_vote" value="Vote">
<?php echo form_close(); ?>
三江源。