I can’t combine 2 arrays into 1, arrays are formed from the mysql database, array_merge did not help

I need 1 array to completely merge, thank you in advance, I’m very much counting on your help

My code is php Model (it forms and combines arrays)

 public function get_Product_from_Att ($ att_id, $ att_value_id) {

     $ query = $ this-> db-> query ("SELECT * FROM` import_attribute_values` WHERE `id` = '$ att_value_id'");
     $ res = $ query-> row;

 $ ImportAttValue = trim ($ res ['idimport']);


 $ query = $ this-> db-> query ("SELECT * FROM` os_product_attribute` WHERE `attribute_id` = '$ att_id' and` text` = '$ ImportAttValue' ");
 $ product_ids = $ query-> rows;


 foreach ($ product_ids as $ product_id) {

   $ product_id = $ product_id ['product_id'];

     $ query = $ this-> db-> query ("SELECT * FROM` os_product` WHERE `product_id` = '$ product_id'");
     $ row1 = $ query-> rows;

     $ query = $ this-> db-> query ("SELECT * FROM` os_product_description` WHERE `product_id` = '$ product_id'");
     $ row2 = $ query-> rows;   

 $ result = array_merge ($ row1, $ row2);    


 }

 return $ result;     

     }

The output is 2 arrays, but you need one

Array ([0] => Array ([product_id] => 7 [model] => 2018 [sku] => [upc] => 659737 [ean] => 84x108 / 32 [jan] => solid [isbn] = > 978-5-17-109810-0, 978-0-000-00000-2, 978-0-000-00000-2 [mpn] => 320 [location] => [quantity] => 100 [stock_status_id] => 7 [image] => catalog / import_files / dir_pic / 659737.jpg [manufacturer_id] => 4 [shipping] => 1 [options_buy] => 0 [price] => 300.0000 [points] => 0 [tax_class_id] => 0 [date_available] => 0000-00-00 [weight] => 0.00 [weight_class_id] => 1 [length] => 0.00 [width] => 0.00 [height] => 0.00 [length_class_id] => 1 [ subtract] => 1 [minimum] => 1 [sort_order] => 1 [status] => 1 [viewed] => 5 [date_added] => 0000-00-00 00:00:00 [date_modified] => 0000 -00-00 00:00:00)

[1] => Array ( [product_id] => 7 [language_id] => 1 [name] => Витя Малеев в школе и дома. Повесть и рассказы [description] => <p>В книгу классика детской литературы Н.Н. Носова «Витя Малеев в школе и дома. Повесть и рассказы» вошла повесть о Вите Малееве и рассказы. Герои Носова весёлые и непосредственные. Они умеют дружить и справляться со своими недостатками. В 1952 году Н.Н. Носов за повесть «Витя Малеев в школе и дома» получил Сталинскую премию. В 1954 году по повести был снят фильм «Два друга». Иллюстрации в книге народного художника СССР В.Н. Горяева. Для младшего школьного возраста.</p> [short_description] => [tag] => [meta_title] => Носов Николай Николаевич - Витя Малеев в школе и дома. Повесть и рассказы - 978-5-17-109810-0, 978-0-000-00000-2, 978-0-000-00000-2 [meta_h1] => Витя Малеев в школе и дома. Повесть и рассказы [meta_description] => Продажа книг для взрослых и детей. Витя Малеев в школе и дома. Повесть и рассказы выгодно. Огромный выбор по самым различным тематикам [meta_keyword] => Витя Малеев в школе и дома. Повесть и рассказы, купить, выгодно, в магазине, онлайн )

)

    2 answers 2

    Can still choose everything at once in one query?

     public function get_Product_from_Att($att_id, $att_value_id) { $query = $this->db->query("SELECT * FROM `import_attribute_values` WHERE `id`= '$att_value_id'"); $res = $query->row; $ImportAttValue = trim($res['idimport']); $query = $this->db->query("SELECT * FROM `os_product_attribute` WHERE `attribute_id` = '$att_id' and `text` = '$ImportAttValue'"); $product_ids = $query->rows; foreach ($product_ids as $product_id){ $product_id = $product_id['product_id']; $query = $this->db->query(" SELECT p.*, pd.* FROM `os_product` `p` LEFT JOIN `os_product_description` `pd` ON p.product_id = pd.product_id WHERE p.product_id = '$product_id' "); $row=$query->rows; echo '<pre>'; print_r($row); die; } return $result; } 
    • Well, that would have written everything in one query, all of a sudden, atoms in $ product_ids = $ query-> rows; there will be 100 products. 100 times muskul tugging? Then add "IN ()" to "WHERE p.product_id" and throw all the id products there. - kevin
    • @kevin Suggest your option, if you have a better idea, and in the description indicate the advantages of your option. - Manitikyl
    • one
      I wrote the answer to a specific question - madfan41k
    • Thank you so much madfan41k - Sergey
    • s) why did I put a minus then? - madfan41k

    well or more optimized version

     public function get_Product_from_Att($att_id, $att_value_id) { $query = $this->db->query("SELECT * FROM `import_attribute_values` WHERE `id`= '$att_value_id'"); $res = $query->row; $ImportAttValue = trim($res['idimport']); $query = $this->db->query("SELECT * FROM `os_product_attribute` WHERE `attribute_id` = '$att_id' and `text` = '$ImportAttValue'"); $product_ids = $query->rows; $prodIds = ''; foreach ($product_ids as $pid) { $prodIds .= $pid['product_id'] . ', '; } $res = []; if ($prodIds != '') { $prodIds = substr($prodIds, 0, -2); $query = $this->db->query( "SELECT p.*, pd.* FROM `os_product` `p` LEFT JOIN `os_product_description` `pd` ON p.product_id = pd.product_id WHERE p.product_id IN('{$prodIds}')" ); $res = $query->rows; } return $res; } 

    those. If $ prodIds is empty, then an empty array will return and the base will not twitch at all.

    • $ prodIds = implode (',', $ product_ids); and how will Aydishnikov get there? ))) - madfan41k
    • sorry, didn’t notice that IDs are returned in the associative array from the first request - kevin