Codeigniter - mysql query with variable









up vote
0
down vote

favorite












I need help for the query in my model, I want to find the field with variable that i'm input to the controller and as for right now the problem is that the field won't read my variable so here is the code



Controller



public function tampil_soal()
$kode_soal = $this->input->post('kode_soal');
$where = array('kode_soal' => $kode_soal);
$data['tampilan']= $this->m_model->tampil_soal($kode_soal)->result();
$this->load->view('soal_tampil',$data);



Model



public function tampil_soal($where)
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");



View



<form action="<?php echo base_url()?>siswa/tampil_soal" method="post" class="form">
<input class="input" name="kode_ujian" placeholder="Kode ujian"/>
<input class="button" type="submit" name="submit" value="Selesai"/>
</form>









share|improve this question























  • You are passing $where as an array, while you are not using the key's value for using it as a column in Where condition
    – Madhur Bhaiya
    Nov 12 at 6:27










  • Your code is open to SQL injection related attacks. Please learn to use Prepared Statements
    – Madhur Bhaiya
    Nov 12 at 6:27










  • Have you check $kode_soal get value in controller?
    – Sachin
    Nov 12 at 6:33










  • @Sachin yes i'm already make the view input of the $kode_soal and make sure that it gets the value to the controller but the problem is probably in the model? @MadhurBhaiya what do you mean that is open to SQL injection? is like get easily hacked or something?
    – Happy Dog
    Nov 12 at 6:43










  • can you try echo $this->db->last_query(); so we can find your query is correct or something wrong with query?
    – Sachin
    Nov 12 at 7:50














up vote
0
down vote

favorite












I need help for the query in my model, I want to find the field with variable that i'm input to the controller and as for right now the problem is that the field won't read my variable so here is the code



Controller



public function tampil_soal()
$kode_soal = $this->input->post('kode_soal');
$where = array('kode_soal' => $kode_soal);
$data['tampilan']= $this->m_model->tampil_soal($kode_soal)->result();
$this->load->view('soal_tampil',$data);



Model



public function tampil_soal($where)
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");



View



<form action="<?php echo base_url()?>siswa/tampil_soal" method="post" class="form">
<input class="input" name="kode_ujian" placeholder="Kode ujian"/>
<input class="button" type="submit" name="submit" value="Selesai"/>
</form>









share|improve this question























  • You are passing $where as an array, while you are not using the key's value for using it as a column in Where condition
    – Madhur Bhaiya
    Nov 12 at 6:27










  • Your code is open to SQL injection related attacks. Please learn to use Prepared Statements
    – Madhur Bhaiya
    Nov 12 at 6:27










  • Have you check $kode_soal get value in controller?
    – Sachin
    Nov 12 at 6:33










  • @Sachin yes i'm already make the view input of the $kode_soal and make sure that it gets the value to the controller but the problem is probably in the model? @MadhurBhaiya what do you mean that is open to SQL injection? is like get easily hacked or something?
    – Happy Dog
    Nov 12 at 6:43










  • can you try echo $this->db->last_query(); so we can find your query is correct or something wrong with query?
    – Sachin
    Nov 12 at 7:50












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I need help for the query in my model, I want to find the field with variable that i'm input to the controller and as for right now the problem is that the field won't read my variable so here is the code



Controller



public function tampil_soal()
$kode_soal = $this->input->post('kode_soal');
$where = array('kode_soal' => $kode_soal);
$data['tampilan']= $this->m_model->tampil_soal($kode_soal)->result();
$this->load->view('soal_tampil',$data);



Model



public function tampil_soal($where)
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");



View



<form action="<?php echo base_url()?>siswa/tampil_soal" method="post" class="form">
<input class="input" name="kode_ujian" placeholder="Kode ujian"/>
<input class="button" type="submit" name="submit" value="Selesai"/>
</form>









share|improve this question















I need help for the query in my model, I want to find the field with variable that i'm input to the controller and as for right now the problem is that the field won't read my variable so here is the code



Controller



public function tampil_soal()
$kode_soal = $this->input->post('kode_soal');
$where = array('kode_soal' => $kode_soal);
$data['tampilan']= $this->m_model->tampil_soal($kode_soal)->result();
$this->load->view('soal_tampil',$data);



Model



public function tampil_soal($where)
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");



View



<form action="<?php echo base_url()?>siswa/tampil_soal" method="post" class="form">
<input class="input" name="kode_ujian" placeholder="Kode ujian"/>
<input class="button" type="submit" name="submit" value="Selesai"/>
</form>






php mysql codeigniter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 7:41

























asked Nov 12 at 6:24









Happy Dog

185




185











  • You are passing $where as an array, while you are not using the key's value for using it as a column in Where condition
    – Madhur Bhaiya
    Nov 12 at 6:27










  • Your code is open to SQL injection related attacks. Please learn to use Prepared Statements
    – Madhur Bhaiya
    Nov 12 at 6:27










  • Have you check $kode_soal get value in controller?
    – Sachin
    Nov 12 at 6:33










  • @Sachin yes i'm already make the view input of the $kode_soal and make sure that it gets the value to the controller but the problem is probably in the model? @MadhurBhaiya what do you mean that is open to SQL injection? is like get easily hacked or something?
    – Happy Dog
    Nov 12 at 6:43










  • can you try echo $this->db->last_query(); so we can find your query is correct or something wrong with query?
    – Sachin
    Nov 12 at 7:50
















  • You are passing $where as an array, while you are not using the key's value for using it as a column in Where condition
    – Madhur Bhaiya
    Nov 12 at 6:27










  • Your code is open to SQL injection related attacks. Please learn to use Prepared Statements
    – Madhur Bhaiya
    Nov 12 at 6:27










  • Have you check $kode_soal get value in controller?
    – Sachin
    Nov 12 at 6:33










  • @Sachin yes i'm already make the view input of the $kode_soal and make sure that it gets the value to the controller but the problem is probably in the model? @MadhurBhaiya what do you mean that is open to SQL injection? is like get easily hacked or something?
    – Happy Dog
    Nov 12 at 6:43










  • can you try echo $this->db->last_query(); so we can find your query is correct or something wrong with query?
    – Sachin
    Nov 12 at 7:50















You are passing $where as an array, while you are not using the key's value for using it as a column in Where condition
– Madhur Bhaiya
Nov 12 at 6:27




You are passing $where as an array, while you are not using the key's value for using it as a column in Where condition
– Madhur Bhaiya
Nov 12 at 6:27












Your code is open to SQL injection related attacks. Please learn to use Prepared Statements
– Madhur Bhaiya
Nov 12 at 6:27




Your code is open to SQL injection related attacks. Please learn to use Prepared Statements
– Madhur Bhaiya
Nov 12 at 6:27












Have you check $kode_soal get value in controller?
– Sachin
Nov 12 at 6:33




Have you check $kode_soal get value in controller?
– Sachin
Nov 12 at 6:33












@Sachin yes i'm already make the view input of the $kode_soal and make sure that it gets the value to the controller but the problem is probably in the model? @MadhurBhaiya what do you mean that is open to SQL injection? is like get easily hacked or something?
– Happy Dog
Nov 12 at 6:43




@Sachin yes i'm already make the view input of the $kode_soal and make sure that it gets the value to the controller but the problem is probably in the model? @MadhurBhaiya what do you mean that is open to SQL injection? is like get easily hacked or something?
– Happy Dog
Nov 12 at 6:43












can you try echo $this->db->last_query(); so we can find your query is correct or something wrong with query?
– Sachin
Nov 12 at 7:50




can you try echo $this->db->last_query(); so we can find your query is correct or something wrong with query?
– Sachin
Nov 12 at 7:50












6 Answers
6






active

oldest

votes

















up vote
0
down vote



accepted










View



<form action="<?php echo base_url()?>siswa/tampil_soal" method="post" class="form">
<input class="input" name="kode_ujian" placeholder="Kode ujian"/>
<input class="button" type="submit" name="submit" value="Selesai"/>
</form>


Controller



you are using wrong post name "$this->input->post('kode_soal')" change this to $this->input->post('kode_ujian')
then



public function tampil_soal()
$kode_soal = $this->input->post('kode_ujian');
$where = array('kode_soal' => $kode_soal);
$data['tampilan']= $this->m_model->tampil_soal($kode_soal);
$this->load->view('test',$data);



Model



public function tampil_soal($where)
$qry = $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");
if($qry->num_rows()>0)
return $qry->result();
else
return array();







share|improve this answer




















  • okay this works thank you very much
    – Happy Dog
    Nov 12 at 10:12

















up vote
4
down vote













just try this:



//controller
public function tampil_soal()
$kode_soal = $this->input->post('kode_ujian');
$data['tampilan']= $this->m_model->tampil_soal($kode_soal);
$this->load->view('soal_tampil',$data);



// model
public function tampil_soal($where)
$this->db->where('kode_soal',$where);
return $this->db->get('soal')->result();
// use the return $this->db->get('soal')->row();
// if your query return one record






share|improve this answer






















  • i'm sorry i don't quite understand what you are saying
    – Happy Dog
    Nov 12 at 7:43










  • okay, i will edit the answer as soon as possible
    – Khalifa Nikzad
    Nov 12 at 7:47










  • you used the wrong input name in your controller and I made it correct in code above use the above code it will work
    – Khalifa Nikzad
    Nov 12 at 8:06










  • oh, i see thank you but i already found the answer
    – Happy Dog
    Nov 12 at 10:13

















up vote
0
down vote













I think you have to use result() function with query



public function tampil_soal($where)
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()")->result();






share|improve this answer




















  • isn't the ->result() is for the controller? PS:I have tried it still not working, and it says Call to a member function result() on a non-object
    – Happy Dog
    Nov 12 at 6:44


















up vote
0
down vote













try this query:
//controller



public function tampil_soal()
$data['tampilan']= $this->m_model->tampil_soal($this->input->post('kode_soal');
$this->load->view('soal_tampil',$data);



//model



public function tampil_soal($where)
return $this->db->where('kode_soal',$where)->get('soal')->result();






share|improve this answer




















  • You didn't add the $where on the controller
    – Happy Dog
    Nov 12 at 6:48











  • or is there another way get the $where from the model?
    – Happy Dog
    Nov 12 at 6:52










  • is kode_soal field exists in your datatable?
    – PHP Geek
    Nov 12 at 6:54










  • yes it exists there
    – Happy Dog
    Nov 12 at 7:07

















up vote
0
down vote













Model



public function tampil_soal($where)
$condition = $where;
// Your Condition...
$this->db->where($condition);
// Order By ...
$this->db->order_by('RAND()');
// Return Data from Table ...
return $this->db->get('soal');






share|improve this answer



























    up vote
    0
    down vote













    change this



    public function tampil_soal($where)
    return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");



    to this



    public function tampil_soal($kode_soal)
    return $this->db->query("select * from soal where kode_soal='$kode_soal' ORDER BY RAND()");



    hope it'll helps






    share|improve this answer




















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256869%2fcodeigniter-mysql-query-with-variable%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      6 Answers
      6






      active

      oldest

      votes








      6 Answers
      6






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote



      accepted










      View



      <form action="<?php echo base_url()?>siswa/tampil_soal" method="post" class="form">
      <input class="input" name="kode_ujian" placeholder="Kode ujian"/>
      <input class="button" type="submit" name="submit" value="Selesai"/>
      </form>


      Controller



      you are using wrong post name "$this->input->post('kode_soal')" change this to $this->input->post('kode_ujian')
      then



      public function tampil_soal()
      $kode_soal = $this->input->post('kode_ujian');
      $where = array('kode_soal' => $kode_soal);
      $data['tampilan']= $this->m_model->tampil_soal($kode_soal);
      $this->load->view('test',$data);



      Model



      public function tampil_soal($where)
      $qry = $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");
      if($qry->num_rows()>0)
      return $qry->result();
      else
      return array();







      share|improve this answer




















      • okay this works thank you very much
        – Happy Dog
        Nov 12 at 10:12














      up vote
      0
      down vote



      accepted










      View



      <form action="<?php echo base_url()?>siswa/tampil_soal" method="post" class="form">
      <input class="input" name="kode_ujian" placeholder="Kode ujian"/>
      <input class="button" type="submit" name="submit" value="Selesai"/>
      </form>


      Controller



      you are using wrong post name "$this->input->post('kode_soal')" change this to $this->input->post('kode_ujian')
      then



      public function tampil_soal()
      $kode_soal = $this->input->post('kode_ujian');
      $where = array('kode_soal' => $kode_soal);
      $data['tampilan']= $this->m_model->tampil_soal($kode_soal);
      $this->load->view('test',$data);



      Model



      public function tampil_soal($where)
      $qry = $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");
      if($qry->num_rows()>0)
      return $qry->result();
      else
      return array();







      share|improve this answer




















      • okay this works thank you very much
        – Happy Dog
        Nov 12 at 10:12












      up vote
      0
      down vote



      accepted







      up vote
      0
      down vote



      accepted






      View



      <form action="<?php echo base_url()?>siswa/tampil_soal" method="post" class="form">
      <input class="input" name="kode_ujian" placeholder="Kode ujian"/>
      <input class="button" type="submit" name="submit" value="Selesai"/>
      </form>


      Controller



      you are using wrong post name "$this->input->post('kode_soal')" change this to $this->input->post('kode_ujian')
      then



      public function tampil_soal()
      $kode_soal = $this->input->post('kode_ujian');
      $where = array('kode_soal' => $kode_soal);
      $data['tampilan']= $this->m_model->tampil_soal($kode_soal);
      $this->load->view('test',$data);



      Model



      public function tampil_soal($where)
      $qry = $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");
      if($qry->num_rows()>0)
      return $qry->result();
      else
      return array();







      share|improve this answer












      View



      <form action="<?php echo base_url()?>siswa/tampil_soal" method="post" class="form">
      <input class="input" name="kode_ujian" placeholder="Kode ujian"/>
      <input class="button" type="submit" name="submit" value="Selesai"/>
      </form>


      Controller



      you are using wrong post name "$this->input->post('kode_soal')" change this to $this->input->post('kode_ujian')
      then



      public function tampil_soal()
      $kode_soal = $this->input->post('kode_ujian');
      $where = array('kode_soal' => $kode_soal);
      $data['tampilan']= $this->m_model->tampil_soal($kode_soal);
      $this->load->view('test',$data);



      Model



      public function tampil_soal($where)
      $qry = $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");
      if($qry->num_rows()>0)
      return $qry->result();
      else
      return array();








      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Nov 12 at 8:02









      Faisal Mk

      765




      765











      • okay this works thank you very much
        – Happy Dog
        Nov 12 at 10:12
















      • okay this works thank you very much
        – Happy Dog
        Nov 12 at 10:12















      okay this works thank you very much
      – Happy Dog
      Nov 12 at 10:12




      okay this works thank you very much
      – Happy Dog
      Nov 12 at 10:12












      up vote
      4
      down vote













      just try this:



      //controller
      public function tampil_soal()
      $kode_soal = $this->input->post('kode_ujian');
      $data['tampilan']= $this->m_model->tampil_soal($kode_soal);
      $this->load->view('soal_tampil',$data);



      // model
      public function tampil_soal($where)
      $this->db->where('kode_soal',$where);
      return $this->db->get('soal')->result();
      // use the return $this->db->get('soal')->row();
      // if your query return one record






      share|improve this answer






















      • i'm sorry i don't quite understand what you are saying
        – Happy Dog
        Nov 12 at 7:43










      • okay, i will edit the answer as soon as possible
        – Khalifa Nikzad
        Nov 12 at 7:47










      • you used the wrong input name in your controller and I made it correct in code above use the above code it will work
        – Khalifa Nikzad
        Nov 12 at 8:06










      • oh, i see thank you but i already found the answer
        – Happy Dog
        Nov 12 at 10:13














      up vote
      4
      down vote













      just try this:



      //controller
      public function tampil_soal()
      $kode_soal = $this->input->post('kode_ujian');
      $data['tampilan']= $this->m_model->tampil_soal($kode_soal);
      $this->load->view('soal_tampil',$data);



      // model
      public function tampil_soal($where)
      $this->db->where('kode_soal',$where);
      return $this->db->get('soal')->result();
      // use the return $this->db->get('soal')->row();
      // if your query return one record






      share|improve this answer






















      • i'm sorry i don't quite understand what you are saying
        – Happy Dog
        Nov 12 at 7:43










      • okay, i will edit the answer as soon as possible
        – Khalifa Nikzad
        Nov 12 at 7:47










      • you used the wrong input name in your controller and I made it correct in code above use the above code it will work
        – Khalifa Nikzad
        Nov 12 at 8:06










      • oh, i see thank you but i already found the answer
        – Happy Dog
        Nov 12 at 10:13












      up vote
      4
      down vote










      up vote
      4
      down vote









      just try this:



      //controller
      public function tampil_soal()
      $kode_soal = $this->input->post('kode_ujian');
      $data['tampilan']= $this->m_model->tampil_soal($kode_soal);
      $this->load->view('soal_tampil',$data);



      // model
      public function tampil_soal($where)
      $this->db->where('kode_soal',$where);
      return $this->db->get('soal')->result();
      // use the return $this->db->get('soal')->row();
      // if your query return one record






      share|improve this answer














      just try this:



      //controller
      public function tampil_soal()
      $kode_soal = $this->input->post('kode_ujian');
      $data['tampilan']= $this->m_model->tampil_soal($kode_soal);
      $this->load->view('soal_tampil',$data);



      // model
      public function tampil_soal($where)
      $this->db->where('kode_soal',$where);
      return $this->db->get('soal')->result();
      // use the return $this->db->get('soal')->row();
      // if your query return one record







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 12 at 8:00

























      answered Nov 12 at 7:37









      Khalifa Nikzad

      68811




      68811











      • i'm sorry i don't quite understand what you are saying
        – Happy Dog
        Nov 12 at 7:43










      • okay, i will edit the answer as soon as possible
        – Khalifa Nikzad
        Nov 12 at 7:47










      • you used the wrong input name in your controller and I made it correct in code above use the above code it will work
        – Khalifa Nikzad
        Nov 12 at 8:06










      • oh, i see thank you but i already found the answer
        – Happy Dog
        Nov 12 at 10:13
















      • i'm sorry i don't quite understand what you are saying
        – Happy Dog
        Nov 12 at 7:43










      • okay, i will edit the answer as soon as possible
        – Khalifa Nikzad
        Nov 12 at 7:47










      • you used the wrong input name in your controller and I made it correct in code above use the above code it will work
        – Khalifa Nikzad
        Nov 12 at 8:06










      • oh, i see thank you but i already found the answer
        – Happy Dog
        Nov 12 at 10:13















      i'm sorry i don't quite understand what you are saying
      – Happy Dog
      Nov 12 at 7:43




      i'm sorry i don't quite understand what you are saying
      – Happy Dog
      Nov 12 at 7:43












      okay, i will edit the answer as soon as possible
      – Khalifa Nikzad
      Nov 12 at 7:47




      okay, i will edit the answer as soon as possible
      – Khalifa Nikzad
      Nov 12 at 7:47












      you used the wrong input name in your controller and I made it correct in code above use the above code it will work
      – Khalifa Nikzad
      Nov 12 at 8:06




      you used the wrong input name in your controller and I made it correct in code above use the above code it will work
      – Khalifa Nikzad
      Nov 12 at 8:06












      oh, i see thank you but i already found the answer
      – Happy Dog
      Nov 12 at 10:13




      oh, i see thank you but i already found the answer
      – Happy Dog
      Nov 12 at 10:13










      up vote
      0
      down vote













      I think you have to use result() function with query



      public function tampil_soal($where)
      return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()")->result();






      share|improve this answer




















      • isn't the ->result() is for the controller? PS:I have tried it still not working, and it says Call to a member function result() on a non-object
        – Happy Dog
        Nov 12 at 6:44















      up vote
      0
      down vote













      I think you have to use result() function with query



      public function tampil_soal($where)
      return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()")->result();






      share|improve this answer




















      • isn't the ->result() is for the controller? PS:I have tried it still not working, and it says Call to a member function result() on a non-object
        – Happy Dog
        Nov 12 at 6:44













      up vote
      0
      down vote










      up vote
      0
      down vote









      I think you have to use result() function with query



      public function tampil_soal($where)
      return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()")->result();






      share|improve this answer












      I think you have to use result() function with query



      public function tampil_soal($where)
      return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()")->result();







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Nov 12 at 6:33









      Poonam Navapara

      18618




      18618











      • isn't the ->result() is for the controller? PS:I have tried it still not working, and it says Call to a member function result() on a non-object
        – Happy Dog
        Nov 12 at 6:44

















      • isn't the ->result() is for the controller? PS:I have tried it still not working, and it says Call to a member function result() on a non-object
        – Happy Dog
        Nov 12 at 6:44
















      isn't the ->result() is for the controller? PS:I have tried it still not working, and it says Call to a member function result() on a non-object
      – Happy Dog
      Nov 12 at 6:44





      isn't the ->result() is for the controller? PS:I have tried it still not working, and it says Call to a member function result() on a non-object
      – Happy Dog
      Nov 12 at 6:44











      up vote
      0
      down vote













      try this query:
      //controller



      public function tampil_soal()
      $data['tampilan']= $this->m_model->tampil_soal($this->input->post('kode_soal');
      $this->load->view('soal_tampil',$data);



      //model



      public function tampil_soal($where)
      return $this->db->where('kode_soal',$where)->get('soal')->result();






      share|improve this answer




















      • You didn't add the $where on the controller
        – Happy Dog
        Nov 12 at 6:48











      • or is there another way get the $where from the model?
        – Happy Dog
        Nov 12 at 6:52










      • is kode_soal field exists in your datatable?
        – PHP Geek
        Nov 12 at 6:54










      • yes it exists there
        – Happy Dog
        Nov 12 at 7:07














      up vote
      0
      down vote













      try this query:
      //controller



      public function tampil_soal()
      $data['tampilan']= $this->m_model->tampil_soal($this->input->post('kode_soal');
      $this->load->view('soal_tampil',$data);



      //model



      public function tampil_soal($where)
      return $this->db->where('kode_soal',$where)->get('soal')->result();






      share|improve this answer




















      • You didn't add the $where on the controller
        – Happy Dog
        Nov 12 at 6:48











      • or is there another way get the $where from the model?
        – Happy Dog
        Nov 12 at 6:52










      • is kode_soal field exists in your datatable?
        – PHP Geek
        Nov 12 at 6:54










      • yes it exists there
        – Happy Dog
        Nov 12 at 7:07












      up vote
      0
      down vote










      up vote
      0
      down vote









      try this query:
      //controller



      public function tampil_soal()
      $data['tampilan']= $this->m_model->tampil_soal($this->input->post('kode_soal');
      $this->load->view('soal_tampil',$data);



      //model



      public function tampil_soal($where)
      return $this->db->where('kode_soal',$where)->get('soal')->result();






      share|improve this answer












      try this query:
      //controller



      public function tampil_soal()
      $data['tampilan']= $this->m_model->tampil_soal($this->input->post('kode_soal');
      $this->load->view('soal_tampil',$data);



      //model



      public function tampil_soal($where)
      return $this->db->where('kode_soal',$where)->get('soal')->result();







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Nov 12 at 6:44









      PHP Geek

      1,1691717




      1,1691717











      • You didn't add the $where on the controller
        – Happy Dog
        Nov 12 at 6:48











      • or is there another way get the $where from the model?
        – Happy Dog
        Nov 12 at 6:52










      • is kode_soal field exists in your datatable?
        – PHP Geek
        Nov 12 at 6:54










      • yes it exists there
        – Happy Dog
        Nov 12 at 7:07
















      • You didn't add the $where on the controller
        – Happy Dog
        Nov 12 at 6:48











      • or is there another way get the $where from the model?
        – Happy Dog
        Nov 12 at 6:52










      • is kode_soal field exists in your datatable?
        – PHP Geek
        Nov 12 at 6:54










      • yes it exists there
        – Happy Dog
        Nov 12 at 7:07















      You didn't add the $where on the controller
      – Happy Dog
      Nov 12 at 6:48





      You didn't add the $where on the controller
      – Happy Dog
      Nov 12 at 6:48













      or is there another way get the $where from the model?
      – Happy Dog
      Nov 12 at 6:52




      or is there another way get the $where from the model?
      – Happy Dog
      Nov 12 at 6:52












      is kode_soal field exists in your datatable?
      – PHP Geek
      Nov 12 at 6:54




      is kode_soal field exists in your datatable?
      – PHP Geek
      Nov 12 at 6:54












      yes it exists there
      – Happy Dog
      Nov 12 at 7:07




      yes it exists there
      – Happy Dog
      Nov 12 at 7:07










      up vote
      0
      down vote













      Model



      public function tampil_soal($where)
      $condition = $where;
      // Your Condition...
      $this->db->where($condition);
      // Order By ...
      $this->db->order_by('RAND()');
      // Return Data from Table ...
      return $this->db->get('soal');






      share|improve this answer
























        up vote
        0
        down vote













        Model



        public function tampil_soal($where)
        $condition = $where;
        // Your Condition...
        $this->db->where($condition);
        // Order By ...
        $this->db->order_by('RAND()');
        // Return Data from Table ...
        return $this->db->get('soal');






        share|improve this answer






















          up vote
          0
          down vote










          up vote
          0
          down vote









          Model



          public function tampil_soal($where)
          $condition = $where;
          // Your Condition...
          $this->db->where($condition);
          // Order By ...
          $this->db->order_by('RAND()');
          // Return Data from Table ...
          return $this->db->get('soal');






          share|improve this answer












          Model



          public function tampil_soal($where)
          $condition = $where;
          // Your Condition...
          $this->db->where($condition);
          // Order By ...
          $this->db->order_by('RAND()');
          // Return Data from Table ...
          return $this->db->get('soal');







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 at 8:08









          Darryl Ceguerra

          885




          885




















              up vote
              0
              down vote













              change this



              public function tampil_soal($where)
              return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");



              to this



              public function tampil_soal($kode_soal)
              return $this->db->query("select * from soal where kode_soal='$kode_soal' ORDER BY RAND()");



              hope it'll helps






              share|improve this answer
























                up vote
                0
                down vote













                change this



                public function tampil_soal($where)
                return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");



                to this



                public function tampil_soal($kode_soal)
                return $this->db->query("select * from soal where kode_soal='$kode_soal' ORDER BY RAND()");



                hope it'll helps






                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  change this



                  public function tampil_soal($where)
                  return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");



                  to this



                  public function tampil_soal($kode_soal)
                  return $this->db->query("select * from soal where kode_soal='$kode_soal' ORDER BY RAND()");



                  hope it'll helps






                  share|improve this answer












                  change this



                  public function tampil_soal($where)
                  return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");



                  to this



                  public function tampil_soal($kode_soal)
                  return $this->db->query("select * from soal where kode_soal='$kode_soal' ORDER BY RAND()");



                  hope it'll helps







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 12 at 8:39









                  Rizki Masjahri

                  214




                  214



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256869%2fcodeigniter-mysql-query-with-variable%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Top Tejano songwriter Luis Silva dead of heart attack at 64

                      政党

                      天津地下鉄3号線