【问题标题】:Conditional select from a table using codeigniter使用 codeigniter 从表中进行条件选择
【发布时间】:2017-04-07 15:48:18
【问题描述】:

我正在尝试选择只显示一些信息(条件选择)。

我的意思是,这是我的桌子“usuarios”:

“usuarios”包括:(id、用户名、姓名、姓氏、密码、类型、状态、日期)

看看:

我的目标是选择只显示 "type" = 1 AND "status" = 1 的用户

看看:

我做了一个选择,但它显示了每个用户名,它不验证任何东西:/。

我的程序显示了这一点,但它不正确,因为它没有验证任何内容:/

这是我的代码:

我的控制器文件:

    public function edit($ID){

  $data['usuarios'] = $this->Crudmodel->get_usuarios();
  $data['record']=$this->Crudmodel->get_id_row($ID);
  $this->load->view('edit',$data);

}

我的模型文件:

          public function get_usuarios() {
         $this->db->select('c.*')
             ->from('usuarios c');

       $q = $this->db->get();

          return $q->result();
}

我的“编辑”文件:

    <h2 align="center">UPDATE</h2>
<form method="post" action='<?php echo site_url('Home/saveupdate'); ?>'>
<tr>

    <td><input type="text" hidden name="txtid" value="<?php echo $record->id ?>"/></td>

</tr>
<tr>

    <td>
        <select name="txtcarr">
            <?php foreach($usuarios as $item):?>
            <option value="<?php echo $item->id;?>"><?php echo $item->username;?></option>
             <?php endforeach;?>
        </select>
    </td>
</tr>


<tr>

    <td></td>
    <td><input type="submit" value="Save"/></td>

</tr>

不知道怎么办:/

【问题讨论】:

    标签: php mysql codeigniter fetch


    【解决方案1】:

    为什么不只选择你想要的行?如果你把它放在你的模型中,它会像你期望的那样工作吗?

    public function get_usuarios() {
       $this->db->select('id, username')
            ->from('usuarios')
            ->where(array('status'=>1, 'type'=>1));
    
       $q = $this->db->get();
       return $q->result();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-06
      • 2011-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多