2016-07-25 1 views
0

は、ここに私のモデル関数はCodeIgniterの中にSQLの列の最大値に

public function bids_info($id){ 
      $this->db->select_max('bid_amount'); 
    $this->db->where('product_id', $id); 
    $result = $this->db->get('wc_bids'); 

    $this->db->select('*')->select('wc_bids.id, wc_seller_products.id as p_id') 
    ->from('wc_bids') 
    ->join('wc_buyer', 'wc_bids.buyer_id = wc_buyer.id', 'LEFT') 
    ->join('wc_seller_products', 'wc_bids.product_id = wc_seller_products.id', 'LEFT') 
    ->where('wc_bids.bid_amount',$result); 
    $query = $this->db->get(); 
    } 

でどのように、私は私のproduct_idが22 ここでiが最大bid_amountを取得したいこのwc_bids table image

のようなテーブルwc_bidsを持っていますモデル$ id = 22のように.... plsは適切なクエリを助けます...事前に感謝

+1

使用select_max() - http://www.codeigniter.com/user_guide/database/query_builder.html – rad11

+0

私は私uがそれを使用する方法 – Pardeep

+0

frの動作していないselect_max理由を知りませんか?質問に追加してください – rad11

答えて

0

あなたのモデルをこのように編集してください。

public function bids_info($id) 
{ 
    $this->db->select_max('bid_amount'); 
    $this->db->where('product_id', $id); 
    $result = $this->db->get('wc_bids')->row(); // * Added ->row() 

    $bid_amount = $result['bid_amount']; // * Added this. 

    $this->db->select('*')->select('wc_bids.id, wc_seller_products.id as p_id') 
      ->from('wc_bids') 
      ->join('wc_buyer', 'wc_bids.buyer_id = wc_buyer.id', 'LEFT') 
      ->join('wc_seller_products', 'wc_bids.product_id = wc_seller_products.id', 'LEFT') 
      ->where('wc_bids.bid_amount', $bid_amount); // * Added $bid_amount instead of $result; 
    $query = $this->db->get(); 
} 
関連する問題