Help with Careerjet API pagination

I have been trying to integrate the careerjet API into my webpage and so far have been able to get the results to show on the job search results page.

However, my problem is how to make the script automatically paginate the results. (For instance I get a result like this “found 4533 jobs on 120 pages” ). The default single page is the only one displayed with the default page size of 20 results and the rest of the pages are not shown.

Please can someone take a look at the code and tell me how to make this possible.
Every help is appreciated.

Code below:
[php]<?php
require_once “Services_Careerjet2.php” ;

$api = new Services_Careerjet(‘en_US’) ;

$result = $api->search(array( ‘keywords’ => ‘’,
‘location’ => ‘’,
‘page’ => $page ,)
) ;

if ( $result->type == ‘JOBS’ ){
echo ("

\n");echo “Found “.$result->hits.” jobs” ;
echo " on “.$result->pages.” pages\n" ;echo ("

\n");
echo ("
\n");
$jobs = $result->jobs ;
foreach( $jobs as $job ){
echo ("<table id='job-posts' class='job-posts' cellspacing='0'>\n");

echo ("

\n");
echo ("\n");
echo ("\n");
echo " " .$job->title."\n" ;echo ("
\n");
echo ("
\n");
echo ("\n");echo (“at\n”);echo ("\n");
echo " “.$job->company.”\n" ;

echo ("\n");echo (“in\n”);echo ("\n");
echo " “.$job->locations.”\n";

echo ("</div>\n");

echo ("

\n");
echo ("\n");
echo ("\n");
echo ("</strong></td>\n");

echo ("

\n");
echo ("
\n");
echo “\n” ;
}
}

if ( $result->type == ‘LOCATIONS’ ){
$locations = $result->locations ;
foreach ( $locations as $loc ){
echo $loc."\n" ;
}
}

Basic paging code

if( $page > 1 ){
echo “Use $page - 1 to link to previous page\n”;
}
echo “You are on page $page\n” ;
if ( $page < $result->pages ){
echo “Use $page + 1x to link to next page\n” ;
}
?>
[/php]

The Careerjet_services API code is shown below
[php]<?php

/**

/**

//function Services_Careerjet($base = ‘http://www.careerjet.co.uk’ )
function Services_Careerjet( $locale = ‘en_UK’ )
{
$base = $this->locale2base[$locale] ;
if ( ! $base ){
$base = $this->locale2base[‘en_UK’] ;
}
$this->base = $base ;
}

function call($fname , $args)
{
$url = $this->base.’/devel/’.$fname.’.api?’ ;
foreach ($args as $key => $value){
$url .= $key.’=’.urlencode($value).’&’ ;
}

$response = file_get_contents($url);
return json_decode($response) ;

}

/**

  • Do a search in Careerjet job database
  • Call exemple:
  • $result = $cjapi->search(array( ‘keywords’ => ‘java’,
  •                           'location' => 'London',
    
  •                           'pagesize' => 2 )
    
  •                    );
    
  • @param array $args map of search options
  •                     exemple : array( 'keywords' => 'java manager',
    
  •                                      'location' => 'london' );
    
  •                     See OPTIONS for details about available options.
    
  •                     Values of keys MUST be in ASCII or unicode (utf8)
    
  •                     If you use this API within a webpage, make sure:
    
  •                       - That your pages are served in utf-8 encoding OR
    
  •                       - Your job search form begins like that :
    
  •                          <form accept-charset="UTF-8"
    
  • @return object(stdClass) An object containing results
  •                       If the given location is not ambiguous, you can use this
    
  •                       object like that:
    
  •                       if ( $result->type == 'JOBS' ){
    
  •                          echo "Got ".$result->hits." jobs: \n" ;
    
  •                          echo " On ".$result->pages." pages \n" ;
    
  •                          $jobs = $result->jobs ;
    
  •                          foreach( $jobs as &$job ){
    
  •                              echo " URL: ".$job->url."\n" ;
    
  •                              echo " TITLE: ".$job->title."\n" ;
    
  •                              echo " LOC:   ".$job->locations."\n";
    
  •                              echo " COMPANY: ".$job->company."\n" ;
    
  •                              echo " SALARY: ".$job->salary."\n" ;
    
  •                              echo " DATE:   ".$job->date."\n" ;
    
  •                              echo " DESC:   ".$job->description."\n" ;
    
  •                              echo " SITE:   ".$job->site."\n" ;
    
  •                              echo "\n" ;
    
  •                           }
    
  •                         }
    
  •                       If the given location is ambiguous, result contains
    
  •                       a list of suggested locations:
    
  •                       if ( $result->type == 'LOCATIONS' ){
    
  •                           echo "Suggested locations:\n" ;
    
  •                           $locations = $result->locations ;
    
  •                           foreach ( $locations as &$loc ){
    
  •                               echo $loc."\n" ;
    
  •                           }
    
  •                        }
    
  • OPTIONS
  • All options have default values and are not mandatory
  • keywords     : Keywords to search in job offers. Example: 'java manager'
    
  •                Default : none (All offers in the api country)
    
  • location     : Location to search job offers in. Examples: 'London' , 'Yorkshire' ..
    
  •                Default: none ( All offers in the api country)
    
  • sort         : Type of sort. Can be:
    
  •                 'relevance' (default) - most relevant first 
    
  •                 'date'                - freshest offer first 
    
  •                 'salary'              - biggest salary first
    
  • start_num    : Num of first offer returned in entire result space
    
  •                should be >= 1 and <= Number of hits
    
  •                Default : 1 
    
  • pagesize     : Number of offers returned in one call
    
  •                Default : 20
    
  • page         : Number of the asked page. 
    
  •                should be >=1
    
  •                The max number of page is given by $result->pages
    
  •                If this value is set, the eventually given start_num is overrided
    
  • contracttype : Character code for contract type
    
  •                 'p'    - permanent job
    
  •                 'c'    - contract
    
  •                 't'    - temporary
    
  •                 'i'    - training
    
  •                 'v'    - voluntary
    
  •                Default: none (all contract types)
    
  • contractperiod : Character code for contract work period:
    
  •                   'f'     - Full time
    
  •                   'p'     - Part time
    
  •                  Default: none (all work period)
    

*/
function search($args)
{
$result = $this->call(‘search’ , $args);
if ( $result->type == ‘ERROR’ ){
trigger_error( $result->error );
}
return $result ;
}

var $locale2base = array(
‘cs_CZ’ => “http://www.careerjet.cz”,
‘da_DK’ => “http://www.careerjet.dk”,
‘de_AT’ => “http://www.careerjet.at”,
‘de_CH’ => “http://www.careerjet.ch”,
‘de_DE’ => “http://www.careerjet.de”,
‘en_AE’ => “http://www.careerjet.ae”,
‘en_AU’ => “http://www.careerjet.com.au”,
‘en_CA’ => “http://www.careerjet.ca”,
‘en_CN’ => “http://en.careerjet.cn”,
‘en_HK’ => “http://www.careerjet.hk”,
‘en_IE’ => “http://www.careerjet.ie”,
‘en_IN’ => “http://www.careerjet.co.in”,
‘en_MY’ => “http://www.careerjet.com.my”,
‘en_NZ’ => “http://www.careerjet.co.nz”,
‘en_OM’ => “http://www.careerjet.com.om”,
‘en_PH’ => “http://www.careerjet.ph”,
‘en_PK’ => “http://www.careerjet.com.pk”,
‘en_QA’ => “http://www.careerjet.com.qa”,
‘en_SG’ => “http://www.careerjet.sg”,
‘en_GB’ => “http://www.careerjet.co.uk”,
‘en_UK’ => “http://www.careerjet.co.uk”,
‘en_US’ => “http://www.careerjet.com”,
‘en_ZA’ => “http://www.careerjet.co.za”,
‘en_TW’ => “http://www.careerjet.com.tw”,
‘en_VN’ => “http://www.careerjet.vn”,
‘es_AR’ => “http://www.opcionempleo.com.ar”,
‘es_BO’ => “http://www.opcionempleo.com.bo”,
‘es_CL’ => “http://www.opcionempleo.cl”,
‘es_CR’ => “http://www.opcionempleo.co.cr”,
‘es_DO’ => “http://www.opcionempleo.com.do”,
‘es_EC’ => “http://www.opcionempleo.ec”,
‘es_ES’ => “http://www.opcionempleo.com”,
‘es_GT’ => “http://www.opcionempleo.com.gt” ,
‘es_MX’ => “http://www.opcionempleo.com.mx”,
‘es_PA’ => “http://www.opcionempleo.com.pa”,
‘es_PE’ => “http://www.opcionempleo.com.pe”,
‘es_PR’ => “http://www.opcionempleo.com.pr”,
‘es_PY’ => “http://www.opcionempleo.com.py”,
‘es_UY’ => “http://www.opcionempleo.com.uy”,
‘es_VE’ => “http://www.opcionempleo.com.ve”,
‘fi_FI’ => “http://www.careerjet.fi”,
‘fr_BE’ => “http://www.optioncarriere.be”,
‘fr_CA’ => “http://fr.careerjet.ca” ,
‘fr_CH’ => “http://www.optioncarriere.ch”,
‘fr_FR’ => “http://www.optioncarriere.com”,
‘fr_LU’ => “http://www.optioncarriere.lu”,
‘fr_MA’ => “http://www.optioncarriere.ma”,
‘hu_HU’ => “http://www.careerjet.hu”,
‘it_IT’ => “http://www.careerjet.it”,
‘ja_JP’ => “http://www.careerjet.jp”,
‘ko_KR’ => “http://www.careerjet.co.kr”,
‘nl_BE’ => “http://www.careerjet.be”,
‘nl_NL’ => “http://www.careerjet.nl”,
‘no_NO’ => “http://www.careerjet.no”,
‘pl_PL’ => “http://www.careerjet.pl”,
‘pt_PT’ => “http://www.careerjet.pt”,
‘pt_BR’ => “http://www.careerjet.com.br”,
‘ru_RU’ => “http://www.careerjet.ru”,
‘ru_UA’ => “http://www.careerjet.com.ua”,
‘sv_SE’ => “http://www.careerjet.se”,
‘sk_SK’ => “http://www.careerjet.sk”,
‘tr_TR’ => “http://www.careerjet.com.tr”,
‘uk_UA’ => “http://www.careerjet.ua”,
‘vi_VN’ => “http://www.careerjet.com.vn”,
‘zh_CN’ => “http://www.careerjet.cn

);

}

?>[/php]

Please I look forward to assistance on this matter.
Thanks in advance.

Sponsor our Newsletter | Privacy Policy | Terms of Service