大家好,我刚开始使用 codeigniter 和 php。我正在制作一个简单的调查类型网站,带有复选框,问题将是多项选择,如果选中复选框,结果将存储在数据库中。我的问题是我将如何去做。这是我的表格,并提前感谢大家的帮助。
看法
<?php foreach($survay_data as $survay):?>
<ul>
<li><h1><?php echo $survay->Question;?></h1></li>
<li><?php echo $survay->qA; ?><input type="checkbox" name="q1[]" value="qA"></li>
<li><?php echo $survay->qB; ?><input type="checkbox" name="q2[]" value="qB"></li>
<li><?php echo $survay->qC; ?><input type="checkbox" name="q3[]" value="qC"></li>
<?php endforeach; ?>
<input type="textarea" value='a' name="comment">
<br>
<input type="submit" value="Submit">
</ul>
控制器
<?php
class Survay extends CI_Model{
function dosurvay($arrData){
$this->db->select('QID, Question, qA, qB, qC');
$this->db->from('tblquestions');
$this->db->where('Question', $arrData['Question']);
$this->db->where('qA', $arrData['qA']);
$this->db->where('qB', $arrData['qB']);
$this->db->where('qC', $arrData['qC']);
$this -> db -> limit(1);
$query = $this -> db -> get();
if($query -> num_rows() == 1)
{
return $query->result();
}
else
{
return false;
}
}
}
?>
模型
<?php
class Survaycontroller extends CI_Controller{
// 'QID, Question, qA, qB, qC'
function index()
{
$arrData = array();
$arrData["qA"] = $this->input->post("qA");
$arrData["qB"] = $this->input->post("qB");
$arrData["qC"] = $this->input->post("qC");
$arrData["Question"] = $this->input->post("Question");
$this->load->model('survay');
$survay_data = $this->survay->dosurvay($arrData);
$viewData['survay_data'] = $survay_data;
$this->load->view('survay_view', $viewData);
}
}
?>