更新表中的特定记录将显示表中的其他记录

时间:2013-12-04 06:43:01

标签: php codeigniter

在下面的codeigniter代码中我放置了控制器和型号。在我的会员表中,我有4列考试名称,月份,年份和大学名称。

Exam name month year college name
anna univ feb   2013   kings
anna      sep   2014    srm

现在我的目标是当我登录国王学院时,它会显示特定的大学信息。但是当我更新国王信息时,它也会显示srm信息。请帮助我解决问题。 控制器:

class Exam_site extends ci_controller
{
    function index()
            {   
                    $data = array();
                    $college_name = $this->session->userdata('college_name');
                    if($query = $this->exam_model->get_records($college_name))
                {
                        $data['records'] = $query;
                }

            $this->load->view('exam_view', $data);


          }

          function index1()
    {
        $data            = array();
        $keyword         = $this->input->post('keyword');
        if($keyword!=""){
            $data['results'] = $this->exam_model->search($keyword);
        }
        $this->load->view('exam_view', $data);

    }

    function input()
        {   
            $data = array();

            $this->load->view('exam_view', $data);
        }   





    function manage_customers()
    {
                 $data['title']="Manage Customers";
                 //query model to get data results for form
                 $data=array();

          if($query=$this->exam_model->get_customer_records())

          {
                $data['records']=$query;
          }//end of if bracket

          $editcustomer = $this->input->post('editcustomer');

            if( $this->input->post('editcustomer') != false )

            {

            foreach($editcustomer as $row_id)
                 {
                     $this->form_validation->set_rules("exam_name_" .$row_id,"'exam name'","required");//to show validation in udata screen
                     $this->form_validation->set_rules("month_".$row_id,"`month`","required");//to show validation in udata screen
                     $this->form_validation->set_rules("year_".$row_id,"`year`","required");//to show validation in udata screen

                 }//end of foreach bracket
            }//end of if bracket

            if ($this->form_validation->run() == FALSE)

                {

                     $data["message"]="";
                     $this->load->view("exam_view",$data);
                } //end of if bracket

                else 

                    {

                // single update - working
                if( $this->input->post('editcustomer') != false )
                {
                    foreach ($editcustomer as $row_id)
                    {
                        $data = array( 
                        'college_name' => $this->session->userdata('college_name'),
                        'exam_name' => $this->input->post('exam_name_'.$row_id),
                        'month' => $this->input->post('month_'.$row_id),
                        'year' => $this->input->post('year_'.$row_id),
                        );//end of the array
                 //this is update the data when it click
                 $this->exam_model->update_customer_records( $row_id, $data );

                    }//end of foreach bracket
                 //Not Working   
                  $this->session->set_flashdata('dbaction', 'Selected Records have been updated successfully');
                    redirect('exam_site/manage_customers', 'refresh');
                    }//end of if bracket

            }//end of function
   }

}//end of class

模型:

class Exam_model extends ci_model {



    function get_records($college_name)
    {
        $this->db->where('college_name',$college_name);
        $query = $this->db->get('exam_table');
        return $query->result();

    }

/*  function add_record($data) 
    {
        $this->db->insert('exam_table', $data);
        return;
    }*/

    function update_record($data) 
    {
        $temp = 'exam_name'.$this->uri->segment(3);
        echo "temp:".$temp;
        echo "data:".$this->input->post($temp);
        $data1 = array(

            'exam_name' => $this->input->post('exam_name.$this->uri->segment(3)'),
            'month'=>$this->input->post('month.$this->uri->segment(3)'),
            'year'=>$this->input->post('year.$this->uri->segment(3)')

            );
                echo "exam_name:".$data1['exam_name'];
        echo " month:".$data1['month'];
        echo "year:".$datal['year'];


                }


    function send($data) {
       $this->db->insert('msg', $data);
       return;
    }

    function get_customer_records()
    {
        $query = $this->db->get('exam_table');
        return $query->result();

    }


    function update_customer_records($row_id, $data)
    {

        $this->db->where('id',$row_id);
        $this->db->update('exam_table',$data);  
        if ($this->db->_error_number() == 1451)
                {
                 $this->session->set_flashdata('updatecascade', 'updatecascade');
                }
                if ($this->db->_error_number() == "")
                {
                 $this->session->set_flashdata('update', 'update');
                }
    }



}

1 个答案:

答案 0 :(得分:0)

你能提供$ this-> input-> post('editcustomer')的价值吗?
同样在您的控制器中,您最后缺少一个结束括号}。说//功能结束的注释行实际上是else括号的结尾。