需要一些建议如何正确使用union和result_array。我有不同行的表,但我必须做联合,因为它们必须打印在同一个表行中。
所以没有联盟,我的功能看起来像这样:
function get_all() {
$this->db->select('id, pavadinimas, prekesid, linkas');
$query = $this->db->get('parduotuve');
return $query->result_array();
使用union
function get_all() {
$this->db->select('id, pavadinimas, prekesid, linkas');
$this->db->from('parduotuve');
$query1=$this->db->get()->result();
$this->db->select('kpavadinimas');
$this->db->from('kategorija');
$query2=$this->db->get()->result();
return $query->result_array=array_merge($query1, $query2);
但现在我有错误
Fatal error: Cannot use object of type stdClass as array
在此视图行中:
foreach ($products as $product){
$product_id = $product['id'];
任何想法如何解决它并建立良好的联盟?
EDIT1。
array(4) { [0]=> object(stdClass)#20 (4) { ["id"]=> string(1) "1" ["pavadinimas"]=> string(8) "varle.lt" ["prekesid"]=> string(22) "div[@itemprop="price"]" ["linkas"]=> string(15) "http://varle.lt" }
[1]=> object(stdClass)#21 (4) { ["id"]=> string(1) "2" ["pavadinimas"]=> string(7) "pigu.lt" ["prekesid"]=> string(38) "div[id="price_block"] strong#sellPrice" ["linkas"]=> string(14) "http://pigu.lt" }
[2]=> object(stdClass)#22 (4) { ["id"]=> string(1) "3" ["pavadinimas"]=> string(10) "avitela.lt" ["prekesid"]=> string(9) "sadasdasd" ["linkas"]=> string(6) "asdasd" }
[3]=> object(stdClass)#23 (4) { ["id"]=> string(2) "50" ["pavadinimas"]=> string(4) "dddd" ["prekesid"]=> string(4) "dddd" ["linkas"]=> string(3) "ddd" } }
EDIT2:
现在我明白了:
Error Number: 1096
No tables used
SELECT *
Filename: C:\xampp\htdocs\svetaine\system\database\DB_driver.php
Line Number: 330
和功能
function get_all() {
$this->db->select('id, pavadinimas, prekesid, linkas');
$this->db->from('parduotuve');
$this->db->get()->result_array();;
$query1=$this->db->get()->result();
$this->db->select('kpavadinimas');
$this->db->from('kategorija');
$this->db->get()->result_array();
$query2=$this->db->get()->result();
return array_merge($query1, $query2);
}