我已经为我的问题寻找了一个类似的解决方案,但我很难找到它,所以如果已经问过这个问题,请原谅。我有我的php代码
foreach($data['cells'] as $row) {
print_r($row);
}
产生
Array
(
[1] => ASSET ID
[2] => SERIAL IN CAPS
[3] => COMPANYASSETTAG
[4] => DATE RCVD
[5] => MFR
[6] => Type
[7] => MODEL
[8] => PRINTER MODEL COMMENTS
[9] => PART NUMBER
[10] => R ID
[11] => GRADE
[12] => PRICE
[13] => COLOR CAPABLE (Color or Monochrome)
[14] => COSMETICALLY ACCEPTABLE (Yes or No)
[15] => PRINTERCABLEINCLUDED (Yes or No)
[16] => PRINTER TECHNOLOGY (Laser, Inkjet, 4-1 Laser, 3-1 Laser, 4-1 Ink Jet, 3-1 Ink Jet, Dot Matrix, Plotter, Solid Ink, Thermal)
[17] => DUPLEX (Yes or No)
[18] => MULTIFUNCTION (Yes or No)
[19] => COMMENT (reason)
[20] => COSMETICS COMMENT
[21] => PURCHASE ORDER # (Trailer #)
[22] => WAYBILL#
)
Array
(
[1] => CNGYF04230
[2] => CNGYF04230
[3] => MISSING
[4] => 28/12/2012
[5] => Hewlett Packard
[6] => Multi-Function Printers
[8] => 4345X
[9] => Q3943A
[11] => G
[13] => Monochrome
[14] => Yes
[15] => No
[16] => Laser
[17] => Yes
[18] => Yes
[21] => TRDS293
[22] => HM693800
)
如您所见,与上述数组相比,第二个数组中的键缺失了。这些对应于列。第二个中缺少一些的原因是因为这些字段不包含任何数据。我希望能够根据键将这些插入到 mysql 表中的相应字段中。
例如
foreach($data['cells'] as $row) {
//print_r($row);
$sql = "INSERT INTO table (asset_id,serial_in-caps...) VALUES ('$row[0]','$row[1]'...)";
}