How to put a two-dimensional array in mysql. PHPcode $ SQL = & quot; select * froma & quot; $ result = $ db-& gt; query ($ SQL); while ($ row = mysql_fetch_array ($ result )) {$ How to put a two-dimensional array in mysql.
PHP code
$ SQL = "select * from a"; $ result = $ db-> query ($ SQL); while ($ row = mysql_fetch_array ($ result )) {$ arr ["id"] [] = $ row ["id"]; $ arr ["no"] [] = $ row ["no"]; $ arr ["name"] [] = $ row ["name"];} $ sql2 = "select * from B "; $ result2 = $ db-> query ($ sql2); while ($ row = mysql_fetch_array ($ result2 )) {$ arr2 ["id"] [] = $ row ["id"]; $ arr2 ["address"] [] = $ row ["address"];} function array_diff_rewrite ($ array1, $ array2) {// traverses the key foreach ($ array 1 as $ k => $ v) {// determines whether the array2 array has the same key as array1. if it does not exist, assign it to if (! Isset ($ array2 [$ k]) {$ array2 [$ k] = $ array1 [$ k] ;}return $ array2 ;}$ arr3 = array_diff_rewrite ($ arr, $ arr2); // print_r ($ arr3); function insert ($ array1, $ array2) {foreach ($ array1 as $ k => $ v) {if (! Isset ($ array2 [$ k]) {$ sql4 = "alter table B add $ k varchar (200)" ;}} echo $ sql4;} insert ($ arr3, $ arr2 );
Compare tables A and B. if Table B does not exist in Table A, insert the data that does not exist in Table B.
How can I insert arr3 into Table B? Because some fields in Table B are not... messy ..
Please rescue me...
------ Solution --------------------
Use array_diff_assoc ($ array1, $ array2 );