doushi1510 2014-10-16 15:29
浏览 55
已采纳

未定义的变量Array Slim Application

I am getting this error that runs fine on one of my servers with php 5.4 I transfered the code to a new server with php 5.5.9 and now I am getting this error:

Details

Type: ErrorException Code: 8 Message: Undefined variable: propertylist File: /var/www/subdomains/api/index.php Line: 57 Trace

The code:

$app->get("/propertylist/", function () use ($app, $db) {
$app->response()->header("Content-Type", "application/json");
ob_start('ob_gzhandler');
$req = $app->request();
$bed = $req->get('bed');
$bath = $req->get('bath');
$city = $req->get('city');
$zip = $req->get('zip');
if($bed ==''){$bed=0;}
if($bath ==''){$bath=0;}
if($zip ==''){
$properties = $db->rets_property_listing_mrmls_resi->limit(2500,0)->where("Bedrooms >= ?", $bed)->where("City LIKE ?", "%$city%")->where("BathsTotal >= ?", $bath);
}else{
$properties = $db->rets_property_listing_mrmls_resi->limit(2500,0)->where("Bedrooms >= ?", $bed)->where("ZipCode LIKE ?", "%$zip%")->where("BathsTotal >= ?", $bath);
}
foreach ($properties as $property) {
    $propertylist[] = array(
        "MLSnumber" => $property["MLnumber"],
        "ListPrice" => number_format($property["ListPrice"]),
        "StreetNumber" => $property["StreetNumber"],
        "StreetName" => $property["StreetName"],
        "SqFt" => $property["SquareFootageStructure"],
        "PropertyDescription" => summaryMode($property["PropertyDescription"],15),
        "Bedrooms" => $property["Bedrooms"],
        "BathsTotal" => $property["BathsTotal"],
        "LO_Name" => $property["LO_Name"]
        );
}
echo json_encode($propertylist);
});

展开全部

  • 写回答

2条回答 默认 最新

  • dongsechuan0535 2014-10-16 15:34
    关注

    You need create/define variable before use:

    $app->get("/propertylist/", function () use ($app, $db) {
    $app->response()->header("Content-Type", "application/json");
    ob_start('ob_gzhandler');
    $req = $app->request();
    $bed = $req->get('bed');
    $bath = $req->get('bath');
    $city = $req->get('city');
    $zip = $req->get('zip');
    if($bed ==''){$bed=0;}
    if($bath ==''){$bath=0;}
    if($zip ==''){
    $properties = $db->rets_property_listing_mrmls_resi->limit(2500,0)->where("Bedrooms >= ?", $bed)->where("City LIKE ?", "%$city%")->where("BathsTotal >= ?", $bath);
    }else{
    $properties = $db->rets_property_listing_mrmls_resi->limit(2500,0)->where("Bedrooms >= ?", $bed)->where("ZipCode LIKE ?", "%$zip%")->where("BathsTotal >= ?", $bath);
    }
    
    $propertylist = array(); //Create variable type array
    
    foreach ($properties as $property) {
        $propertylist[] = array(
            "MLSnumber" => $property["MLnumber"],
            "ListPrice" => number_format($property["ListPrice"]),
            "StreetNumber" => $property["StreetNumber"],
            "StreetName" => $property["StreetName"],
            "SqFt" => $property["SquareFootageStructure"],
            "PropertyDescription" => summaryMode($property["PropertyDescription"],15),
            "Bedrooms" => $property["Bedrooms"],
            "BathsTotal" => $property["BathsTotal"],
            "LO_Name" => $property["LO_Name"]
            );
    }
    echo json_encode($propertylist);
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?