Jump to content
Sign in to follow this  
seblondres

Indeed API

Recommended Posts

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 by seb_london

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...