PHP带回所有行而不是请求

时间:2017-04-12 22:25:43

标签: php codeigniter

我有一个查询,它会从表中返回所有行,而不是我指定的字段。你能看到这个错误吗?我使用的是codeigniter。

提前致谢!

unset($conditions);
    $conditions['conditions'] = array("accountid"=>$this->sessionInfo['database_account_id'],
                "DATE_FORMAT(salestart,'%Y-%m-%d')"=>$today,
                "shop"=>"london"
                );
    $conditions['group_by'] = "item";
    $conditions['fields'] = "accountid, item, count(uniqueid) as totalitems, sum(options) as totaloptions, colour";
    $today_sales = $this->Database_Model->selectData("sales",$conditions);

我的模特是:

public function selectData($table,$condition=array()) {
    if(isset($condition['fields'])){
        $fields = $condition['fields'];
    }
    else{
        $fields = "*";
    }
    $this->Database->select('*');
    $this->Database->from($table);
    if(isset($condition['conditions'])){
       $this->Database->where($condition['conditions']);
    }
    if(isset($condition['group_by'])){
        $this->Database->group_by($condition['group_by']);
    }
    if(isset($condition['order_by'])){
        $this->Database->order_by($condition['order_by']);
    }
    if(isset($condition['where_in'])){
        $where_in = $condition['where_in'];


        foreach($where_in as $key =>$value){
            $this->Database->where_in($key,$value);
         }
    }
    if(isset($condition['joins'])){
        $joins = $condition['joins'];
        foreach($joins as $join){
            $this->Database->join($join['table'], $join['joinWith'],$join['type']);
         }
    }
     $query = $this->Database->get();

     return $query->result_array();
}

1 个答案:

答案 0 :(得分:0)

更改此

$this->Database->select('*');

到这个

$this->Database->select($fields);