我遇到了工作问题我试图使用
提供的值$row['make']
从导入中提取我们数据库中的纯文本数据。现在,当我运行此代码时遇到问题,我得到了这个
Notice: Undefined index: FORDX in convert.php on line 203
我不确定为什么会这样,我猜它与我访问阵列的方式有关。
这是数组
$makes = array(
"ACURA" => "Acura",//does not exist
"AMRTR" => "American",
"ATLAS" => "Atlas",//does not exist
"BRRTR" => "Barrett",
"BMWXX" => "BMW", //does not exist
"BRAE" => "Brae", //does not exist
"BUDDX" => "Budd",
"BUICK" => "Buick", //does not exist
"BUTLR" => "Butler",
"CDLLC" => "Cadillac", //does not exist
"CNDCR" => "Can. Car",//does not exist
"CPCTY" => "Capacity",
"CPTRB" => "Capital",//does not exist
"CARRR" => "Carrier",//does not exist
"CHVRL" => "Chevrolet",
"CHRYS" => "Chrysler", //does not exist
"CLARK" => "Clark", //does not exist
"CLLMN" => "Collins", //does not exist
"CMMRC" => "Commercial Truck", //does not exist
"CMMTR" => "Commercial Truck", //does not exist
"CMMVN" => "Commercial Vans", //does not exist
"CRANE" => "Crane Carrier", //does not exist
"CRNFR" => "Crane Fruehauf", //does not exist
"DATSN" => "Datsun", //does not exist
"DMNDB" => "Diamond B.", //does not exist
"DMNRE" => "Diamond Reo",
"DODGE" => "Dodge",
"DORSY" => "Dorsey",
"DRBTR" => "Durabody", //does not exist
"EASTX" => "East",
"ESPAR" => "Espar", //does not exist
"FNTCN" => "Fontaine",
"FNTTR" => "Fontaine",
"FORDX" => "Ford",
"FRDLT" => "Ford",
"FRGHT" => "Freightliner",
"FRECS" => "Frght Custom Chassis",
"FRUHF" => "Fruehauf",
"FRYEX" => "Frye", //does not exist
"GMXXX" => "GM", //does not exist
"GMCCL" => "GMC",
"GMCXX" => "GMC",
"GRAY" => "Grays", //does not exist
"GRTDN" => "Great Dane",
"GRMAL" => "Grumman", //does not exist
"HEILX" => "Heil",
"HIAB" => "Hiab", //does not exist
"HGHTR" => "Highway", //does not exist
"HINMT" => "Hino", //does not exist
"HBBMF" => "Hobbs",
"HOBBS" => "Hobbs", //does not exist
"HOLND" => "Holland",
"HLLEQ" => "Holland Equipment", //does not exist
"HLLND" => "Holland Hitch Co", //does not exist
"HTCHN" => "Hutchens", //does not exist
"HTCIN" => "Hutchinson", //does not exist
"HYSTER" => "Hyster",
"INGRN" => "Ingersoll Rand",
"IHT" => "International",
"ISUZU" => "Isuzu",
"KNTCK" => "Kentucky",
"KNWRT" => "Kenworth",
"KINDRON" => "Kindron", //does not exist
"KNGTB" => "King's", //does not exist
"KRHNR" => "Krohnert",//does not exist
"LAMDR" => "Land Rover", //does not exist
"LFKTR" => "Lufkin",
"MACK" => "Mack",
"MCKTR" => "Mack",
"MACKX" => "Mack",
"MANAC" => "Manac",
"MTLTR" => "Matlock", //does not exist
"MXNIN" => "Maxon",//does not exist
"MAZDA" => "Mazda",//does not exist
"MRCBN" => "Mercedes-Benz",
"MERC" => "Mercury",//does not exist
"MCKBD" => "Mickey",//does not exist
"MILLR" => "Miller",
"MISCX" => "Miscellaneous",//does not exist
"MITSUB" => "Mitsubishi",
"FUSOX" => "Mitsubishi",
"MTSBS" => "Mitsubishi",
"MNDIN" => "Mond",//does not exist
"MONON" => "Monon",
"MORGN" => "Morgan",//does not exist
"MNCPW" => "Munchie",//does not exist
"M2" => "M2",//does not exist
"NVSTR" => "Navistar",//does not exist
"NSSDA" => "Nissan",//does not exist
"NSSMT" => "Nissan",
"OTHER" => "Other",
"OTTST" => "Ottawa",
"PALFGR" => "Palfinger", //does not exist
"PTRBL" => "Peterbilt",
"PTRSN" => "Peterson",//does not exist,
"PINES" => "Pines",
"POLAR" => "Polar",
"PONT" => "Pontiac",//does not exist
"PRVST" => "Prevost",//does not exist
"PRINC" => "Princeton",//does not exist
"RELIA" => "Reliable",//does not exist
"RENLT" => "Renault",//does not exist
"RSSIN" => "Roussy",//does not exist
"SATRN" => "Saturn",//does not exist
"STDMN" => "Steadman",//does not exist
"STRLG" => "Sterling",
"STWDR" => "Stewart",//does not exist
"STGHT" => "Stoughton",//does not exist
"STRCK" => "Strick",//does not exist
"SUPRR" => "Superior",//does not exist
"SPRRT" => "Superior Tech",//does not exist
"SUPRM" => "Supreme",//does not exist
"THRKN" => "Thermo King",//does not exist
"TIMPT" => "Timpte",
"TOYOT" => "Toyota",//does not exist
"TRLMT" => "Trailermaster",//does not exist
"TRLMB" => "Trailmobile",
"TRLCN" => "Trailmobile",
"TRNSI" => "Transicold",//does not exist
"TRNST" => "Transit",//does not exist
"TRIM" => "Trim",//does not exist
"UTILIT" => "Utilit",//does not exist
"UTLTY" => "Utility",
"VLVNA" => "Volvo",//does not exist
"VOLVO" => "Volvo",
"WABSH" => "Wabash",
"WALKR" => "Walker",
"WARNI" => "Warner",//does not exist
"WEBST" => "Webasto",//does not exist
"WSTNK" => "Westank",//does not exist
"WSTST" => "Western Star",
"WSTAR" => "Westinghouse Air",//does not exist
"WHITE" => "White"
);
我通过$行循环播放数据库中的示例数据[' make']
FORDX VOLVO VOLVO VOLVO VOLVO VOLVO VOLVO VOLVO VOLVO VOLVO VOLVO VOLVO VOLVO VOLVO VOLVO VOLVO VOLVO VOLVO GRTDN GRTDN
这是循环代码
$result = $pdo->prepare("SELECT * FROM csvImport limit 20");
$data = array();
if ($result->execute()) {
while($row = $result->fetch(PDO::FETCH_ASSOC))
{
if($row['status']== "P-Sale Pending")
$status = "Pend";
else
$status = "Live";
$unit = $row['unit'];//stocknumber
$make = $makes[$row['make']];
}
}
答案 0 :(得分:0)
我知道这不是一个答案,而是一个调试提示 - 但在评论中格式化是不够的。
试试这个:
if (isset($makes[$row['make']]) {
$make = $makes[$row['make']];
} else {
echo "unrecognized make for unit {$unit}: ";
var_dump($row['make']);
die();
}
...我敢打赌其中一行中有某种空白字符' make
列...