如何读取具有两个值的表(Codeigniter)

时间:2016-02-10 14:38:28

标签: php database codeigniter

我正在使用 Codeigniter

我的功能有效,但我想做出改变,我无法知道如何做到这一点。

我的功能是读取" status_offre_id" = 1。

但我希望它能够阅读" status_offer_id" = 1 AND" status_offer_id" = 2

到目前为止,我试过这个:

'status_offer_id' => (1 AND 2),
'status_offer_id' => 1,2,
('status_offer_id' => 1) AND ('status_offer_id' => 2), 

and more
<?php  
function showOffer(){

  $idCompany = $_SESSION["company"]["id"];
  $conditions = array(
          'company_id' => $idCompany,
          'status_offer_id' => 1,
    );

  $offer_published = $this->offer_model->lire("*", $conditions);

  $data = array();
  $data["offer"]=$offer_published;

  $this->_layoutHaut();
  $this->load->view('Company/offer_view', $data);
  $this->_layoutBas();
}
?>
  public function lire($selection = "*", $conditions = array(), $champs_order = "id", $direction_ordre = "ASC", $nombre_limite = NULL, $debut_limite = NULL){
$retour= $this->db->select($selection)
                    /*à partir de quelle table*/
                    ->from($this->table)
                    /*déterminer des conditions spécifiques*/
                    ->where($conditions)
                    /*déterminer un ordre précis*/
                    ->order_by($champs_order, $direction_ordre)
                    /*déterminer une limite*/
                    ->limit($nombre_limite, $debut_limite)
                    /*obtenir les résultats (va de pair avec result()*/
                    ->get()
                    /*retourner les résultats sous forme de tableau*/
                    ->result_array();

                    return $retour;

}

3 个答案:

答案 0 :(得分:1)

试试这个:

$conditions = '(company_id = "' . $idCompany . '" AND status_offer_id IN (1, 2))';

答案 1 :(得分:0)

Ur使用具有有效记录的CI,尝试使用它们

$this->db->select("*")
->from($table)
->where('company_id', $company_id)
->where('status_offer_id', 1)
->or_where('status_offer_id',2)

答案 2 :(得分:0)

&#13;
&#13;
$where = (select * from your_table where status_offer_id IN (1, 2));
$this->db->where('company_id', $company_id);
$this->db->where($where);
&#13;
&#13;
&#13;