Parts No Mfg Cond LowPrice AvgPrice HighPrice Weighted TotalQty
002805-00 3COM NEW 25 25 25 N/A 1
0231A085 3COM NEW 133.75 133.75 133.75 N/A 3
0231A61N 3COM NEW 253.58 253.58 253.58 N/A 2
0231A61P 3COM NEW 467.25 467.25 467.25 N/A 1
我只希望将此 csv 格式的 partno 、 mfg 和 price 添加到具有不同字段名称的表中,如第一行中定义的那样,但表中还包含一些其他字段。
这是正确的插入方式??????建议。
if (($handle = fopen("sample.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
$i=0;
if ($scount == 0) {
foreach ($data as $key=>$value){
$item[$i++] = $value;
if($value == 'Parts No') $c1 = $key;
if($value == 'Mfg') $c2 = $key;if($value == 'Cond') $c3 = $key;
if($value == 'AvgPrice') $c4 = $key;
}
}else{
if($data[$c3] == "NEW" || $data[$c3] == "new"){
mysql_query("insert into vable (partno,brand,price)
values('".$data[$c1]."','".$data[$c2]."','".$data[$c4]."') ",);}
}
$scount++;
}