2018-11-12 06:24
浏览 77

Codeigniter - 带变量的mysql查询

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


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();


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


<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"/>

图片转代码服务由CSDN问答提供 功能建议

我需要模型中的查询帮助,我想找到我输入的变量字段 控制器和现在问题是该字段不会读取我的变量所以这里是代码</ p>

控制器</ strong> </ p> \ n

  public function tampil_soal(){
 $ kode_soal = $ this-&gt; input-&gt; post('kode_soal'); 
 $ where = array('kode_soal'=&gt; $ kode_soal)  ; 
 $ data ['tampilan'] = $ this-&gt; m_model-&gt; tampil_soal($ kode_soal) - &gt; result(); 
 $ this-&gt; load-&gt; view('soal_tampil',$ 数据); 
 </ code> </ pre> 

模型</ strong> </ p>

  public function tampil_soal($  where){
 return $ this-&gt; db-&gt; query(“select * from soal where kode_soal ='$ where'ORDER BY RAND()”); 
 </ code> </ pre>  

查看</ strong> </ p>

 &lt; form action =“&lt;?php echo base_url()?&gt; siswa / tampil_soal”  method =“post”class =“form”&gt; 
&lt; input class =“inpu  t“name =”kode_ujian“placeholder =”Kode ujian“/&gt; 
&lt; input class =”button“type =”submit“name =”submit“value =”Selesai“/&gt; 
&lt; / form&gt;  
 </ code> </ pre> 
 </ div>

6条回答 默认 最新

相关推荐 更多相似问题