Sunday, 15 August 2010

Php Multi-Dimensional Array / MySql problem -


I Breaking the content I am trying to write a PHP script that down to a text file enter into a MySQL database, The code is as follows:

  $ file = "my_file.txt"; $ Db = "db_name"; $ Link = mysql_connect ("localhost", "root"); If (! $ Link) dies ("Connection failed"); Mysql_select_db ($ db) or die ("$ db could not open:" .mysql_error (). "& Lt; br / & gt;"); $ Fp = fopen ($ file, 'r') or die ("file can not be opened"); $ My_filesize = filesize ($ file); While ((Fif ($ fp)) {$ prod_doc. = Fread ($ fp, $ my_filesize); // Store the file in a variable} $ prod_array = explode ( "~", $ prod_doc); // ($ i = 0; $ i & lt; Create an array with the explosion function count ($ prod_array); $ i + +) {$ prod_items [$ i] = explode ( ',', $ prod_array [$ i]) ; // Create a Maltese-dimensional array} into the $ query = "my_table (feild1, feild two, feild three) value ( '$ prod_items [$ i] [0]', '$ prod_items [$ i] [1] ',' $ Prod_items [$ i] [2] ') "; $ result = mysql_query ($ query); if (! die $ result) (mysql_error ()); $ result = mysql_ Prbavit_ro ($ result); return $ Results; mysql_close ($ Link); My problem is: Array [0], Array [1], Array [3] which has been entered in the database instead of my data Thanks in advance, Cheers   

You have to repeat your $ prod_items array as well, then assume value $ insert = array ($ I = 0; $ i & lt; Count ($ prod_array); $ i ++) {$ prod_items [$ i] = Explosion (',', $ prod_array [$ i]); // a Maltese-dimensional array insert $ [] = '('. $ Prod_items [$ i] [0]. ','. $ Prod_items [$ i] [1]. ','. $ Prod_items [$ i ] [3]. ')'; } $ Insert_string = implode (',', $ insert); $ Query = "Enter in my_table (feild1, feild two, feild three) Value" $ Insert_string;

And you should use insted for it.


No comments:

Post a Comment