代码:
<?php
if($this->input->post('insert'))
{
$data = array(
'college_name' => $college_name,
'name' => $_POST['name'],
'student_id' => $student_id,
'email' => $_POST['email'],
'mobile' => $_POST['phone'],
'city' => $_POST['city'],
'course' => $_POST['course'],
'inquiry' => $_POST['inquiry'],
'query' => $_POST['query'],
'date' => date('Y-m-d')
);
$query = $this->db->insert('college_contact',$data);
if($query == true)
{
echo "<script>alert('your enquiry submitted successfully');</script>";
}
$this->db->select('name');
$this->db->from('college_contact');
$where = "student_id = '$student_id'";
$this->db->where($where);
$query = $this->db->get();
$result = $query->num_rows();
if($result > 0)
{
echo "you are not allow";
}
}
?>
我是codeigniter的新手。在这段代码中,我创建了表单并将其值插入到数据库中,现在我希望如果某个特定的学生将5个时间数据插入表中,那么就不允许他将更多数据插入到数据库中。那么,我该怎么办呢?请帮帮我。
谢谢
答案 0 :(得分:0)
当您必须在签入模型时插入学生: 试试这种方式,可能会有所帮助。
$student_id = your student id which you get while inserting.
$query =$this->db->select('your_student_id')
->from('college_contact')
->where('your_student_id',$student_id)
->get();
//Now Find Number of rows
$number_of_rows = $query->num_rows();
if($number_of_rows < 5){
//Put your insert query here
} else {
// Redirector gives the message that you have already inserted 5 times..or whatever you want in the message.
}
答案 1 :(得分:0)
我想,
步骤:1,首先,您在表格中选择了行数userid='$userid'
,您将获得当前学生记录数。未将工作数据插入第一个。
步骤:2,继续工作以插入记录或不允许插入条件为
的记录if($record > 5){
echo "not allowed new record";
}else{
//continue insert query work
*$query = $this->db->insert('college_contact',$data);*
echo "your record is inserted";
}
我的意思是,如果当前的学生被录取了5次,我不能获得新的记录。所以,我首先选择他的记录数和连续状态。谢谢。