tommyinnn Posted January 21, 2009 Share Posted January 21, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/141782-assigning-variable-help/ Share on other sites More sharing options...
cytech Posted January 21, 2009 Share Posted January 21, 2009 Try: if ($yearBuilt==NULL){ echo "no results"; }else{ echo $yearBuilt; } If that doesn't work try: $yearBuilt = $value->return_value("yearBuilt",TRUE); if ($yearBuilt==NULL){ echo "no results"; }else{ echo $yearBuilt; } Quote Link to comment https://forums.phpfreaks.com/topic/141782-assigning-variable-help/#findComment-742271 Share on other sites More sharing options...
tommyinnn Posted January 21, 2009 Author Share Posted January 21, 2009 Yea, thanks but I already tried that. Quote Link to comment https://forums.phpfreaks.com/topic/141782-assigning-variable-help/#findComment-742275 Share on other sites More sharing options...
premiso Posted January 21, 2009 Share Posted January 21, 2009 Yea, thanks but I already tried that. You are using a class, we do not know what class or how your class works to solve this issue for you. Does the class return null? If not that null check will never work. Quote Link to comment https://forums.phpfreaks.com/topic/141782-assigning-variable-help/#findComment-742277 Share on other sites More sharing options...
tommyinnn Posted January 21, 2009 Author Share Posted January 21, 2009 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) ?> Quote Link to comment https://forums.phpfreaks.com/topic/141782-assigning-variable-help/#findComment-742285 Share on other sites More sharing options...
premiso Posted January 21, 2009 Share Posted January 21, 2009 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). Quote Link to comment https://forums.phpfreaks.com/topic/141782-assigning-variable-help/#findComment-742286 Share on other sites More sharing options...
tommyinnn Posted January 21, 2009 Author Share Posted January 21, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/141782-assigning-variable-help/#findComment-742295 Share on other sites More sharing options...
premiso Posted January 21, 2009 Share Posted January 21, 2009 Can you post what the "return_value" function actually does? It sounds like it echos it. Without knowing exactly what that does we are at a loss for helping you... Quote Link to comment https://forums.phpfreaks.com/topic/141782-assigning-variable-help/#findComment-742298 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.