php - Retrieve a single row from Codeigniter -
if need retrieve single row of data database, why can't when want insert id table:
'user_id' => $query->row()->id
is there way without foreach loop if want single piece of data?
the full code is:
$this->db->where('username', $this->input->post('username')); $query = $this->db->get('members'); $data = array( 'first' => $this->input->post('first'), 'last' => $this->input->post('last'), 'email' => $this->input->post('email'), 'phone' => $this->input->post('phone'), 'address' => $this->input->post('address'), 'city' => $this->input->post('city'), 'state' => $this->input->post('state'), 'zip' => $this->input->post('zip'), 'comments' => $this->input->post('comments'), 'username' => $this->input->post('username'), 'user_id' => $query->row()->id ); $this->db->insert('contact', $data);
$query->row()->id
correct, yes. given field called 'id' in table, , row exists want. can check $query->num_rows()
see how many rows returned.
Comments
Post a Comment