Tuesday 15 May 2012

php - Undefined variable Array Slim Application -



php - Undefined variable Array Slim Application -

i getting error runs fine on 1 of servers php 5.4 transfered code new server php 5.5.9 , getting 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 () utilize ($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 ?", "%$city%")->where("bathstotal >= ?", $bath); }else{ $properties = $db->rets_property_listing_mrmls_resi->limit(2500,0)->where("bedrooms >= ?", $bed)->where("zipcode ?", "%$zip%")->where("bathstotal >= ?", $bath); } foreach ($properties $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); });

you need create/define variable before use:

$app->get("/propertylist/", function () utilize ($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 ?", "%$city%")->where("bathstotal >= ?", $bath); }else{ $properties = $db->rets_property_listing_mrmls_resi->limit(2500,0)->where("bedrooms >= ?", $bed)->where("zipcode ?", "%$zip%")->where("bathstotal >= ?", $bath); } $propertylist = array(); //create variable type array foreach ($properties $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); });

php arrays

No comments:

Post a Comment