Итак, моя база данных для продуктов структурирована следующим образом:
Код: Выделить всё
products table:
p_id | title | descr | etc
product_attrs table:
attr_id | products.p_id | name | value
Если я пытаюсь получить все сведения о продукте в одном запросе, например это:
Код: Выделить всё
this->db->select('products.title,
p.description,
p.price,
p.stock,
p.name,
p.value');
$this->db->from('p');
$this->db->where('p.p_id', $id);
$this->db->join('product_attrs', 'product_attrs.product_id = p.p_id', 'inner');
$result = $this->db->get();
return $result->result_array();
Код: Выделить всё
Array (
[0] => Array (
[title] => Modest Swimsuit - Full body
[description] => UV +50 Protection - Chlorine Resistant - Water Resistant - Quick Drying - Maximum Breathe Ability- Sea Water Resistant
[price] => 59.95
[stock] => 20
[name] => Brand
[value] => Modestly Active Swimwear
)
[1] => Array (
[title] => Modest Swimsuit - Full body
[description] => UV +50 Protection - Chlorine Resistant - Water Resistant - Quick Drying - Maximum Breathe Ability- Sea Water Resistant
[price] => 59.95
[stock] => 20
[name] => Colour
[value] => Black and Light Blue
)
[2] => Array (
[title] => Modest Swimsuit - Full body
[description] => UV +50 Protection - Chlorine Resistant - Water Resistant - Quick Drying - Maximum Breathe Ability- Sea Water Resistant
[price] => 59.95
[stock] => 20
[name] => size
[value] => small
)
[3] => Array (
[title] => Modest Swimsuit - Full body
[description] => UV +50 Protection - Chlorine Resistant - Water Resistant - Quick Drying - Maximum Breathe Ability- Sea Water Resistant
[price] => 59.95
[stock] => 20
[name] => size
[value] => medium
)
[4] => Array (
[title] => Modest Swimsuit - Full body
[description] => UV +50 Protection - Chlorine Resistant - Water Resistant - Quick Drying - Maximum Breathe Ability- Sea Water Resistant
[price] => 59.95
[stock] => 20
[name] => size
[value] => large
)
)
Код: Выделить всё
$this->db->select('p.title,
p.description,
p.price,
p.stock');
$this->db->from('p');
$this->db->where('p_id', $id);
$result = $this->db->get();
$this->db->select('name, value');
$this->db->from('product_attrs');
$this->db->where('p_id', $id);
$result2 = $this->db->get();
РЕДАКТИРОВАТЬ:
Я сейчас ищу функцию array_merge() в php.net, но если я сделаю это:
Код: Выделить всё
$result = $this->db->get();
$array1 = $result->result_array();
$result2 = $this->db->get();
$array2 = $result2->result_array();
$data = array_merge($array1,$array2);
return $data;
Код: Выделить всё
Array (
[0] => Array (
[title] => Modest Swimsuit - Full body
[description] => UV +50 Protection - Chlorine Resistant - Water Resistant - Quick Drying - Maximum Breathe Ability- Sea Water Resistant
[price] => 59.95
[stock] => 20
)
[1] => Array (
[name] => Brand
[value] => Modestly Active Swimwear
)
[2] => Array (
[name] => Colour
[value] => Black and Light Blue
)
[3] => Array (
[name] => size
[value] => small
)
[4] => Array (
[name] => size
[value] => medium
)
[5] => Array (
[name] => size
[value] => large
)
)
Подробнее здесь: https://stackoverflow.com/questions/151 ... e-table-in