in Education by
I already can update my data from database but the problem is i just want to update one data, but when I enter the new data it updated all of data in the database table like this this is View: user/update_user_data">
this is model: function update_data($id = FALSE) { if($id == FALSE){ $query = $this->db->get('user'); return $query->result_array(); } $query = $this->db->get_where('user', array('id' => $id)); return $query->row_array(); } public function update_user_data($data) { $data = array('firstname' => $this->input->post('firstname'), 'lastname' => $this->input->post('lastname'), 'fullname' => $this->input->post('fullname') ); $this->db->update("user", $data); } this is controller: public function update_data($id = NULL) { $data['us'] = $this->User_Model->update_data($id); if (empty($data['us'])) { show_404(); } $this->load->view('user/update-user', $data); } public function update_user_data() { $data['title'] = 'Update user'; $this->load->library('upload'); $data = array('upload_data' => $this->upload->data()); $this->User_Model->update_user_data($data); redirect('user/index'); } Im just a beginner please respect thanks If there is something wrong with my code please let me know. Its working by the way, the only problem is once I update the users data it updating all of the data in the database. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You are modifying every row in the table because of you have not given any specific row. And for this reason every row is updated after update code runs. you should use below code function update_data($id = FALSE) { if($id == FALSE){ $query = $this->db->get('user'); return $query->result_array(); } $query = $this->db->get_where('user', array('id' => $id)); return $query->row_array(); } public function update_user_data($data) { $data = array('firstname' => $this->input->post('firstname'), 'lastname' => $this->input->post('lastname'), 'fullname' => $this->input->post('fullname') ); $this->db->where('id','1')->update("user", $data); //change id as require your own need }

Related questions

0 votes
    I have a big table which contains about 100 million records in MySQL. I want to read all the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Aug 1, 2022 in Education by JackTerrance
0 votes
    How to set same number 'priority' with one query for Mercedes. +--------------------- ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I've come to this code, but from this i have to manually insert all columns and check it by each ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    We have a live MySQL database that is 99% INSERTs, around 100 per second. We want to archive the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    I want to use python to connect to a MySQL database, how can I do that? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    Why does this mysql query fail? UPDATE accounts SET motivation = IF(motivation+100...
asked Jul 30, 2022 in Education by JackTerrance
0 votes
    I'm trying to set the ideal performance setup for MySQL and resources needed on a shared hosting. My ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 30, 2022 in Education by JackTerrance
0 votes
    The text data I have for a column in database in an enterprise application (uses hibernate) is huge and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    The text data I have for a column in database in an enterprise application (uses hibernate) is huge and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 19, 2022 in Education by JackTerrance
0 votes
    The text data I have for a column in database in an enterprise application (uses hibernate) is huge and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 16, 2022 in Education by JackTerrance
0 votes
    I have some data that looks like this: C:10 R:200 N/A E:3 N/A N:77 I'm trying to ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I get an error stating that there is incorrect syntax near the key word INNER. I wish to delete ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    I get an error stating that there is incorrect syntax near the key word INNER. I wish to delete ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    If I have a table with results like this: 0001400OL 0578400OL 354085OL 48679OL and if I wanted to replace ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    My goal is to merge tables from different schema into one single schema so I would like to execute this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
...