phpmysqlcodeigniter

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.


Solution

  • I think the $idtemp in '' can't be recognized as the real id, it's still $idtemp, you need to put it in "".

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