Jump to content

Recommended Posts

Hi all! I wondered if someone could help me, I'm trying to get a if / else statement to work..

 

this code will produce either nothing or a year (ie. 1986) - it's for a real estate script (Zillow) - It would be the year the home was built

 

$value->return_value("yearBuilt",TRUE)

 

As most of you may know, the below code won't work

 

if ($d==NULL)

  echo "no results";

else

  echo $yearBuilt;

 

I guess what I need to do is assign a variable to the code .. something like

 

$YEAR = $value->return_value("yearBuilt",TRUE)

 

But I can't figure out how to do this.. can anyone point me in the right direction? Thanks!

 

 

Link to comment
https://forums.phpfreaks.com/topic/141782-assigning-variable-help/
Share on other sites

Here's a demo, http://i-locate.info/zillow.php?address=2710E%20Ridge%20Rd&zip=28144

 

but, in the finished code, it will display 20 results, some will return the real estate data, some will not...

the results that do not have any data, I don't want anything to display.

 

Here's the complete code , it came from the Zillow API Forums.

 

<?php

class get_home_value{

 

private $hostname = 'http://www.zillow.com/webservice/GetDeepSearchResults.htm?';

public $zwsid;

 

public function fetch_info($address,$zip){

$path = "zws-id=".$this->zwsid."&address=".urlencode($address)."&citystatezip=".$zip;

$url = $this->hostname.$path;

$p = xml_parser_create();

xml_parse_into_struct($p,file_get_contents($url),$results,$index);

xml_parser_free($p);

$this->results=$results;

$this->index=$index;

 

}

 

 

public function return_value($attribute,$return_echo){

$results=$this->results;

$index= $this->index;

$value=$results[$index[strtoupper($attribute)][0]][value];

 

if($return_echo==TRUE){

echo $value;

}

else return $value;

 

 

}

 

 

}

 

$address=$_REQUEST['address'];

$zip=$_REQUEST['zip'];

$form_submitted=$_REQUEST['form_submitted'];

if (!$form_submitted==1){

 

}

 

 

 

////END OF CLASS

 

 

 

 

 

 

//////Create new instance/////

$value= new get_home_value();

 

 

 

/////Your zwsid here//////

 

$value->zwsid = "<ZILLOW API KEY HERE >";

 

//////Make call and save data to memory////

 

$value->fetch_info($address,$zip);

 

 

 

////Acessing the values is easy. Just call them by tag name. Upper or lowercase is fine////

 

//// TRUE will echo the value and FALSE will return the value.

 

//// This is for demo purposes you can delete it after you get the point////

 

?>

 

 

<?php echo "Tax Assessor Value: $".number_format($value->return_value("taxassessment",FALSE),2); ?>

<p><BR />

  <?php echo "Zestimate: $".number_format($value->return_value("amount",FALSE),2); ?><BR />

  <?php echo "Bedroom(s): ".number_format($value->return_value("bedrooms",FALSE),2); ?><BR />

  <?php echo "Bathroom(s):".number_format($value->return_value("bathrooms",FALSE),2); ?><BR />

Year Built :

<?php $value->return_value("yearBuilt",TRUE) ?>

 

 

Most likely it is not returning null instead an empty string. Also to check null you need to use is_null

 

Try this:


$yearBuilt =  $value->return_value("yearBuilt",TRUE);

if (is_null($yearBuilt) || empty($yearBuilt)){
  echo "no results";
}else{
  echo $yearBuilt;
}

 

Should work just fine.

 

FYI for future reference please place code in [.code][./code] tags (no period).

Thanks, but in a way I tried that as well..

 

$yearBuilt =  $value->return_value("yearBuilt",TRUE);

echo $yearBuilt;

 

does not return anything ,

 

 

 

This does...

 

$value->return_value("yearBuilt",TRUE)

 

 

I've even tried using a hidden field

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.