0
TABLE WORKSHOPS
--------------------------------
id|course_id|country_id|city_id|
--------------------------------
1 | 5 | 1 | 2 |
--------------------------------
2 | 5 | 1 | 4 |
--------------------------------
3 | 5 | 2 | 5 |
--------------------------------
SQL獲取數據,從加入並獲得結果作爲assosiative陣列
TABLE WORKSHOP_DATES
----------------------------------------
id|start_date | end_date | workshop_id |
----------------------------------------
1 |2014-11-05 |2014-11-06| 1 |
----------------------------------------
2 |2014-11-28 |2014-11-29| 1 |
----------------------------------------
3 |2014-11-28 |2014-11-30| 1 |
----------------------------------------
我使用下面的查詢
$this->db->select("$this->_table.*, $_courses_table.name as course, $_countries_table.name as country, $_cities_table.name as city, $_workshop_dates_table.id as workshop_dates_id, $_workshop_dates_table.start_date as start_date, $_workshop_dates_table.end_date as end_date");
$this->db->join("$_courses_table", "$_courses_table.id = $this->_table.ktw_course_id");
$this->db->join("$_countries_table", "$_countries_table.id = $this->_table.ktw_country_id");
$this->db->join("$_cities_table", "$_cities_table.id = $this->_table.ktw_city_id");
$this->db->join("$_workshop_dates_table", "$_workshop_dates_table.ktw_workshop_id = $this->_table.id");
$this->db->where('ktw_course_id', $course_id);
$this->db->group_by("$_workshop_dates_table.ktw_workshop_id");
$this->db->order_by('start_date', 'ASC');
return $this->db->get($this->_table);
但結果是:
Array
(
[0] => stdClass Object
(
[id] => 7
[price] => 1300
[discount] => 13
[early_bird_date] => 2014-12-30
[timing] =>
[batch] =>
[slug] =>
[status] => 1
[ktw_course_id] => 5
[ktw_country_id] => 2
[ktw_city_id] => 5
[ktw_timeslot_id] => 0
[ktw_training_mode_id] => 3
[ktw_currency_id] => 6
[created] =>
[modified] =>
[course] => jquery
[country] => kuwait
[city] => dubai
[workshop_dates_id] => 7
[start_date] => 2014-11-04
[end_date] => 2015-01-05
)
[1] => stdClass Object
(
[id] => 5
[price] => 900
[discount] => 13
[early_bird_date] => 2014-11-26
[timing] =>
[batch] =>
[slug] =>
[status] => 0
[ktw_course_id] => 5
[ktw_country_id] => 1
[ktw_city_id] => 2
[ktw_timeslot_id] => 0
[ktw_training_mode_id] => 1
[ktw_currency_id] => 1
[created] =>
[modified] => 2014-11-14 14:34:29
[course] => jquery
[country] => india
[city] => vizag
[workshop_dates_id] => 2
[start_date] => 2014-11-28
[end_date] => 2014-11-29
)
但我需要這樣(所有workshop_date S有來在數組中的特定workshop_id)
array(
[0] => stdClass Object
(
[id] => 6
[price] => 1300
[discount] => 13
[early_bird_date] => 2014-12-30
[timing] =>
[batch] =>
[slug] =>
[status] => 0
[ktw_course_id] => 5
[ktw_country_id] => 1
[ktw_city_id] => 4
[ktw_timeslot_id] => 0
[ktw_training_mode_id] => 2
[ktw_currency_id] => 1
[created] =>
[modified] => 2014-11-25 10:16:58
[course] => jquery
[country] => india
[city] => hyderabad
[workshop_dates] => array ([0]
[start_date] => 2014-12-30
[end_date] => 2014-12-31
[1]
[start_date] => 2014-11-28
[end_date] => 2014-12-29
[2]
[start_date] => 2014-11-28
[end_date] => 2014-12-30
)
)
我想它作爲關聯數組,一個當然可以有多個車間,同時它可以有多個日期