2017-07-06 1 views
1

コード:codeigniterの5行すべてでuseridが同じで、テーブルに5行挿入した後にユーザーを停止する方法はありますか?

<?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

'$ result> 0'を' 4'に変更することができます –

+0

一定期間または生涯にわたって5つの挿入物に制限したいですか? – GeorgeGeorgitsis

+0

まったく、 '$ result> 5'これは私が意味していたものです。 –

答えて

0

ステップ:1、まず、あなたがuserid='$userid'テーブル内の行数を選択し、あなたが最初に挿入され、現在の学生のレコードcount.Not作業データを取得します。

ステップ:2、あなたが条件でレコードを挿入することを可能にレコードを挿入したりしないように作業を続け、私は現在学生recored場合、新しいレコードに許さ5 times.Soでない意味

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"; 
} 

を気に入って、私が最初に選択します彼の記録数と連続的な条件。ありがとう。

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. 
    } 
関連する問題