0

この mysql クエリがあり、CodeIgniter は初めてです。この mysql クエリを CodeIgniter の Active Record に変換するにはどうすればよいですか?

SELECT chp_destination, cde_name, chp_year, chp_from, chp_to, chp_budget_price_high, 
chp_medium_price_high, chp_luxury_price_high, chp_budget_price_low, chp_medium_price_low, chp_luxury_price_low, chp_timestamp, chp_comment , MAX( chp_timestamp ) AS last_updated, MAX( chp_id )
FROM crm_hotel_price
LEFT JOIN crm_destinations ON cde_id = chp_destination
GROUP BY chp_destination, chp_year
ORDER BY chp_id
4

3 に答える 3

2

これを試してください:(参考)

$this->db->select('chp_destination, cde_name, chp_year, chp_from, chp_to, chp_budget_price_high, chp_medium_price_high, chp_luxury_price_high, chp_budget_price_low, chp_medium_price_low, chp_luxury_price_low, chp_timestamp, chp_comment, MAX(chp_timestamp) AS last_updated, MAX(chp_id)', FALSE);
$this->db->join('crm_destinations', 'cde_id = chp_destination', 'left');
$this->db->group_by('chp_destination, chp_year');
$this->db->order_by('chp_id');
$qry = $this->db->get('crm_hotel_price');
$res = $qry->result(); // or $qry->result_array();
于 2013-08-14T13:28:49.820 に答える
0

このコードを試してください:

 > $this->db->select('chp_destination, cde_name, chp_year, chp_from, chp_to, chp_budget_price_high, 

chp_medium_price_high, chp_luxury_price_high, chp_budget_price_low, chp_medium_price_low, chp_luxury_price_low, chp_timestamp, chp_comment, MAX( chp_timestamp ) AS last_updated, MAX( chp_id )');

$this->db->from('crm_hotel_price');
$this->db->join('crm_destinations','cde_id = chp_destination','LEFT'); // 別のテーブルと結合
$this->db->group_by('chp_destination,chp_year'); // フィールドのグループ化
$this->db->order_by("chp_id", "asc"); // フィールド値のソート用
$query = $this->db->get();
$query->result_array(); を返します。// 結果を返し
、この行を使用して SQL クエリ全体を表示します。
echo $this->db->last_query();

于 2013-10-28T08:56:45.883 に答える
0

試す:

$rs = $this->db->select('chp_destination, cde_name, chp_year, chp_from, chp_to, chp_budget_price_high, chp_medium_price_high, chp_luxury_price_high, chp_budget_price_low, chp_medium_price_low, chp_luxury_price_low, chp_timestamp, chp_comment , MAX( chp_timestamp ) AS last_updated, MAX( chp_id )', false)
      ->from('crm_hotel_price')
      ->join('crm_destinations', 'cde_id = chp_destination', 'LEFT')
      ->group_by(array('chp_destination', 'chp_year'))
      ->order_by('chp_id')
      ->get()->result_array();
于 2013-08-14T13:29:37.463 に答える