2017-05-28 2 views
0

動的代入値型は、クエリが機能していないため、エラー "データベースエラー"を示しています。 'where句'の 'avgRateVal'列が不明です。 ( '1)avgRateValとして、ラウンド(AVG(ratevalue)')、それをするために行うことが可能な限り最高の、何かアドバイスcodeigniterクエリの動的代入値型フィルタ

$this->db->select('round(avg(ratevalue),1) as avgRateVal'); 
if($minRating!=0) 
    $this->db->where('avgRateVal >=', 1); 

if($maxRating!=0) 
    $this->db->where('avgRateVal <=', 5); 
+0

は、SQL https://stackoverflow.com/questions/25160875/filter-rows-based-on-column-values-in-mysql-queryのためのソリューションを得たが、 codeigniterで実装する方法を教えてください。 – santanu

答えて

1

場合($ minRating!= 0)

$this->db->where('round(avg(ratevalue),1) >=', 1); 

場合。

はこのようなクエリを書く:

$this->db->select('round(avg(ratevalue),1) as avgRateVal'); 
if($minRating!=0) 
    $this->db->having('avgRateVal >=', 1); 

if($maxRating!=0) 
    $this->db->having('avgRateVal <=', 5); 
$this->db->get('Table_Name'); 
$this->db->result_array(); 
+0

が無効です。助けてくれてありがとう – santanu

+0

このコードを読んでくださいhttps://www.codeigniter.com/userguide2/database/active_record.htmlあなたはcodeigniterのアクティブなレコード@santanuについてより良い考えを得ることができます – Nidhi

+0

help @ Nidhi – santanu

0

ます$ this-> DB->を選択どのようなものです。

あなたが唯一のGROUP BY、ORDER BY、またはHAVING句で列の別名を使用することができます($ maxRating!= 0)

$this->db->where('round(avg(ratevalue),1) <=', 5); 
+0

は既にそれを試しました。データベースエラーを表示しているので動作していません。 - グループ関数 – santanu

関連する問題