Welcome Guest, Not a member yet? Register   Sign In
Array Problems
#1

[eluser]datguru[/eluser]
HI everyone first of tahnks for reading....

What I am trying to do is join two array for example..

Code:
foreach($product_parts as $row)
        {
            $this->mdl_raw_materials->raw_materials_id = $row->id_of_selected_type;
            $raw_materials = $this->mdl_raw_materials->get();
            $product_parts_tmp = array_merge($raw_materials,$product_parts);
            //$raw_materials_tmp = array_merge($raw_materials,$raw_materials_tmp);

        }

That code produces something like the following....
Quote:Array ( [0] => stdClass Object ( [raw_materials_id] => 7 [raw_materials_description] => 2 x 4s [raw_materials_unit_weight] => 1.14 [raw_materials_part_no] => 365 [raw_materials_supplier_name] => Test3 [raw_materials_unit_price] => 1.1 [raw_materials_min_order_quantity] => 150 ) [1] => stdClass Object ( [id] => 3 [product_id] => 7 [type] => raw_material [id_of_selected_type] => 2 [qty_of_selected_type] => 2 ) [2] => stdClass Object ( [id] => 4 [product_id] => 7 [type] => raw_material [id_of_selected_type] => 2 [qty_of_selected_type] => 2 ) [3] => stdClass Object ( [id] => 6 [product_id] => 7 [type] => raw_material [id_of_selected_type] => 9 [qty_of_selected_type] => 2 ) [4] => stdClass Object ( [id] => 7 [product_id] => 7 [type] => raw_material [id_of_selected_type] => 8 [qty_of_selected_type] => 2 ) [5] => stdClass Object ( [id] => 8 [product_id] => 7 [type] => raw_material [id_of_selected_type] => 7 [qty_of_selected_type] => 2 ) )

Now as you can see what it has done is its combined them but not in the way I intended, I want all the data to go into position 0 for the first lot then poistion 1 for the next. So really I want element[0] and element[1] to be combined into 1 array so [0] and then element [3] and [4] into another so [1] I can explain better with an example.

I want this...
Quote:( [0] => stdClass Object ( [raw_materials_id] => 7 [raw_materials_description] => 2 x 4s [raw_materials_unit_weight] => 1.14 [raw_materials_part_no] => 365 [raw_materials_supplier_name] => Test3 [raw_materials_unit_price] => 1.1 [raw_materials_min_order_quantity] => 150 ) [1] => stdClass Object ( [id] => 3 [product_id] => 7 [type] => raw_material [id_of_selected_type] => 2 [qty_of_selected_type] => 2 )

To look like this....
Quote:( [0] => stdClass Object ( [raw_materials_id] => 7 [raw_materials_description] => 2 x 4s [raw_materials_unit_weight] => 1.14 [raw_materials_part_no] => 365 [raw_materials_supplier_name] => Test3 [raw_materials_unit_price] => 1.1 [raw_materials_min_order_quantity] => 150 [id] => 3 [product_id] => 7 [type] => raw_material [id_of_selected_type] => 2 [qty_of_selected_type] => 2 )

Hope that makes sense... I am trying to combine two mysql querys together so I can draw information from two tables. I was thinking a JOIN would be a better way to go about it but I dont think it will work with the data I have.

Thanks again..

Regards

Chris
#2

[eluser]Krzemo[/eluser]
If those two tables have fields to be joined on - join will be cleaner and much faster solution. Databases are ment to do those things. If they don't I can't see any possibility to do it via arrays reliably.




Theme © iAndrew 2016 - Forum software by © MyBB