代码:
<?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次数据插入到表中,那么他将不被允许向数据库中插入更多的数据。那么,我该怎么做呢?请帮帮我。
谢谢
发布于 2017-07-06 18:09:13
我认为,
步骤:1,首先在表中选择行计数userid='$userid',将当前学生记录count.Not作业数据插入到第一个位置。
步骤: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 times.So,我首先选择了他的记录计数和连续的condition.Thank。
发布于 2017-07-06 18:02:11
当你必须检入你的模型时,学生插入:试着这样做,可能会有帮助。
$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.
}https://stackoverflow.com/questions/44945587
复制相似问题