2016-07-25 4 views
0

Hier ist meine Modellfunktion, wie Maximalwert einer Spalte in SQL in codeigniter

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(); 
    } 

und ich habe Tabelle wc_bids wie diese wc_bids table image

i maximal bid_amount holen wollen, wo mein product_id 22 Wie in Modell $ ID = 22 .... bitte helfen Sie mir die richtige Abfrage ... Vielen Dank im Voraus

+1

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

+0

ich weiß nicht, warum fr mich select_max nicht funktioniert – Pardeep

+0

How u es verwenden? fügen Sie es zu Frage – rad11

Antwort

0

Bearbeiten Sie Ihr Modell als dies.

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(); 
}