Reply to multidimensional array in to a MySQL table

Your name:

Reply:


Posted by Stephen Preston on 03/14/06 02:34

Trying to load an multidimensional array into a MySQL table with columns as
follows,

level1,level2,level3,illust,item,description,partNo,qua,price,remarks,weight
,size,mass

the array first line is $input[0][level1]Engine
the array secondline is $input[0][level2]Cylinder Head
etc..

A 'foreach' inside a 'foreach' echo of the array gives the following, which
is correct.

0, level1, Engine
0, level2, Cylinder Head
0, level3,
0, illust, 001.pdf
0, item, 1
0, description, Casting
0, partNo, 238356
0, qua, 1
0, price, 1,245.00
0, remarks, This is for the Z350 series
0, weight, 5
0, size, 5x5x5
0, mass, 37
1, level1, Engine
1, level2, Cylinder Head
1, level3,
1, illust, 001.pdf
1, item, 2
1, description, Valve, inlet
1, partNo, 452790
1, qua, 4
1, price, 5.46
1, remarks, This is for the Z350 series
1, weight, 5
1, size, 5x5x5
1, mass, 37
2, level1, Engine
2, level2, Cylinder Head
2, level3,
2, illust, 001.pdf
2, item, 3
2, description, Valve, exhaust
2, partNo, 345436
2, qua, 4
2, price, 5.99
2, remarks, This is for the Z350 series
2, weight, 5
2, size, 5x5x5
2, mass, 37

etc..

I have used the print_r to see all the data in the array also.
I've tried the extract() function on the first key which I assume is also an
array, inside and outside the loop to get at the column headings.

I've tried allsorts of while and for loops but can't seem to work out how to
get down to the last key to get the following statement to work. I'm trying
the get the array to work through the first key [0] to fill the row, then
the next key [1] to fill the next row in the table etc..

$query2 = "INSERT INTO $tableName
(level1,level2,level3,illust,item,description,partNo,qua,price,remarks,weigh
t,size,mass) VALUES
('$level1','$level2','$level3','$illust','$item','$description','$partNo','$
qua','$price','$remarks','$weight','$size','$mass')";
$result = mysql_query($query2) or die("Couldn't insert data.");

If I knock out the loops and have the above as a single statement, I can get
the last row of records into the table.

Hope someone can put a novice out of his misery.

Thanks
Stephen

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация