rochellecanale Posted September 25, 2012 Share Posted September 25, 2012 hello guys i have a problem. All i want is to pass my information coming from my multidimensional array. I try to create a function named r_implode that extract array into string but i dont know how to put it in the database. here's my code hope you can help me. //get array information $products = unserialize($this->session->userdata('product_list')); //print array information, works well foreach($products as $element => $inner_array){ echo "<strong>Product ID: ".$element."</strong><br>"; foreach($inner_array as $items){ echo $items."<br>"; } } //HOw CAN I PASS THE ARRAY INFORMATION TO MY DATABASE? //extract array into string works well function r_implode( $glue, $pieces ){ foreach( $pieces as $r_pieces ){ if( is_array( $r_pieces )){ $retVal[] = r_implode( $glue, $r_pieces ); }else{ $retVal[] = $r_pieces; } } return implode( $glue, $retVal ); } echo r_implode(',',$products)."\n"; example of my array layout: Product ID: 2 2 NOKIA 5110 Cellphone 500.00 1 500 NOKI2012-84353 Product ID: 3 3 HP IPAQ RW6828 Cellphone 1500.00 1 1500 HP I2012-08386 Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 25, 2012 Share Posted September 25, 2012 Don't implode it into a string! Loop through the array and Use MySQL multi insert syntax to create all the new rows you need. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.