Juliana Sucahya
Juliana Sucahya

Reputation: 77

update a row using selected id in codeigniter

In my view, i printed all the record in my table. and i made a button for update a row by passing its id to model. when i printed the variable that i used to get the id, it printed. but when i put it in a query, the query result was empty. could someone please help me, what's wrong with my code?

here is my view code

echo " <tr><td width='250' name='tanya'>$row->pertanyaan</td>
               <td name='jawab'>$row->jawaban</td>
               <td width='90'><a href='c_faq/edit?id=".$row->id_faq."' class='btn btn-default' role='button'><i class='glyphicon glyphicon-edit'></i></a>
               <button><span class='glyphicon glyphicon-remove'> </span></button></a>
               </td>
               </tr>";

this is my controller

public function edit()
{
    $data["edits"] = $this->m_faq->acts();
    $this->load->view('v_editfaq', $data);
}

and this is my models

public function acts()
{
    $idtemp = $this->input->get('id');
    $query= $this->db->query('select * from faq where id_faq = "$idtemp"');
    return $query->result();
}

when i printed the $idtemp , it got the right id. but after i put it in $query, the result was empty.

Upvotes: 1

Views: 1047

Answers (2)

Sanjuktha
Sanjuktha

Reputation: 1085

row_array returns a single result and result_array returns multiple results which is usually used for loop cases.

Change the query->result to query->row in query-

$this->db->select('*');
$this->db->from('faq');
$this->db->where('id_faq',$idtemp);
$result=$this->db->get()->row(); //change result to row
 return $result;

Also replace your double quotes in $data["edits"] to $data['edits'] in your controller.

documentation on- row_array & result_array

Upvotes: 1

suibber
suibber

Reputation: 267

i think the $idtemp in '' cant berecognize to real id, it's still $idtemp,you need to put it in ""

$query= $this->db->query("select * from faq where id_faq = '$idtemp'");

Upvotes: 0

Related Questions