doushi1510 2014-10-16 23: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 23: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条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器