seblondres Posted February 20, 2016 Share Posted February 20, 2016 (edited) Hi, I'm trying to detect whether <totalresults> = 0 from the Indeed API. Here is the code I'm using: <?php $search ='oihhb'; $xml = simplexml_load_file('http://api.indeed.com/ads/apisearch?publisher=xxxxxx&q='.$search.'&l=&sort=&radius=&st=&jt=&start='.$start.'&limit=1&fromage=&filter=&latlong=1&co=fr&chnl=&userip=1.2.3.4&useragent=Mozilla/%2F4.0%28Firefox%29&v=2'); foreach($xml->results->result as $result) if ($xml->totalresults == 0) { echo 'empty'; } else { echo $xml->totalresults; } ?> As you can see from the code above, I'm searching for $search ='oihhb'; which purposely doesn't return any results - see <query> below: <response version="2"> <query>oihhb</query> <location/> <dupefilter>true</dupefilter> <highlight>false</highlight> <totalresults>0</totalresults> <start>0</start> <end>0</end> <pageNumber>0</pageNumber> <results></results> </response> So I want to do, it's to echo 'empty' if <totalresults> = 0 but I can't get it work i.e. I can't print 'empty'. However I have to say that I can print the total number of results: echo $xml->totalresults; So must be something wrong with if ($xml->totalresults == 0). If someone could point me to the right direction. Many Thanks, Edited February 20, 2016 by seb_london Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now