首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当codeigniter中的5行userid都相同时,如何在表中插入5行后停止用户?

问当codeigniter中的5行userid都相同时,如何在表中插入5行后停止用户?
EN

Stack Overflow用户
提问于 2017-07-06 17:54:03
回答 2查看 60关注 0票数 1

代码:

代码语言:javascript
复制
<?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次数据插入到表中,那么他将不被允许向数据库中插入更多的数据。那么,我该怎么做呢?请帮帮我。

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-07-06 18:09:13

我认为,

步骤:1,首先在表中选择行计数userid='$userid',将当前学生记录count.Not作业数据插入到第一个位置。

步骤:2、继续插入记录或不允许插入有条件点赞记录

代码语言:javascript
复制
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。

票数 0
EN

Stack Overflow用户

发布于 2017-07-06 18:02:11

当你必须检入你的模型时,学生插入:试着这样做,可能会有帮助。

代码语言:javascript
复制
$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.
   }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44945587

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档