我正在尝试使用通过使用提供的值的工作问题

$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"
);


当我循环通过$ row ['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']];
    }
}

最佳答案

我知道这不是答案,而是调试提示-但注释格式不足。

尝试这个:

if (isset($makes[$row['make']]) {
    $make = $makes[$row['make']];
} else {
    echo "unrecognized make for unit {$unit}: ";
    var_dump($row['make']);
    die();
}


...我敢打赌,行的make列之一中存在某种空格字符...

关于php - 访问关联数组php pdo时出现问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31301750/

10-14 15:22
查看更多