PHP Help Needed

golk75

Regular Member
Joined
Jul 25, 2010
Messages
240
Reaction score
26
Could some one help me with a small php script?
post here if you could help me and I will send you the code to look over
Thanks!.
 
Code:
<?php
$publisher = "xxxxxxxxxxxxxxxx";
$sort = "relevance";  ## Sort by "relevance" or "date"
$radius = "50";  ## Distance from search location
$st = "";  ## Site type (default blank- can set to "jobsite" or "employer")
$jt = "";  ## Job type (default blank- can set to fulltime, parttime, contract, internship, or temporary)
$start_number = 0;  ## Start search results at this number (used for pagination)
$limit = "10";  ## Number of results per page
$fromage = "";  ## Number of days to search back (default blank = 30)
$highlght = "1";  ## Bold the keyword search terms in results (set to 0 for no bold)
$filter = "1";  ## Filters out duplicate results (set to 0 for no filter)
$latlong = "1";  ## If latlong=1, returns latitude and longitude information for each result
$co = "us";  ## Country to search jobs in
$chnl = "";  ## API Channel request.  Leave blank for none
$query = "web analytics";
$location = "55403";
$highlight = "1";
$userip = $_SERVER['REMOTE_ADDR'];  ## IP address of user
$useragent = $_SERVER['HTTP_USER_AGENT'];  ## User's browser type    

$params =
       array(
                'publisher' => $publisher,
                'q' => $query,
                'l' => $location,
                'sort' => $sort,
                'radius' => $radius,
                'st' => $st,
                'jt' => $jt,
                'start' => $start_number,
                'limit' => $limit,
                'fromage' => $fromage,
                'filter' => $filter,
                'latlong' => $latlong,
                'co' => $co,
                'chnl' => $chnl,
                'userip' => $userip,
                'useragent' => $useragent,
                 );


$url = 'http://api.indeed.com/ads/apisearch'.'?'.http_build_query($params,'', '&');

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
$result = curl_exec($ch);
curl_close($ch);

$xml = (simplexml_load_file($url));
$xmlobj = $xml;

foreach ($xmlobj->results->result as $job) {
   echo sprintf("%s<br>\n%s<br><br>\n\n", (string)$job->jobtitle,
(string)$job->snippet); }
?>

<html>

<body>

<ol>



<li>

<p>

<strong>Job :<a href="<?php echo $result['job'][$i]['jobtitle']; ?>" target="_blank"><?php echo $result['result'][$i]['jobtitle']; ?></a></strong>

</p>



</li>


</ol>

</body>

</html>
 
Well here is the code.
i am trying to retrieve search results from indeed.com API and then display the results in my page, but I just can't make it work.
 
Here you go bud (working example: http://crazyflx.com/indeed/):

EDIT: Forgot to say what I changed. The code was missing "v=2" in the URL to query. Just added $version = "2" as a variable and then added v = $version in the params array (and changed up how you were attempting to echo things back of course, which would not have worked even if you had gotten the URL to query correct).

Code:
<?php 

$publisher = "##############";
$sort = "relevance";  ## Sort by "relevance" or "date"
$radius = "50";  ## Distance from search location
$st = "";  ## Site type (default blank- can set to "jobsite" or "employer")
$jt = "";  ## Job type (default blank- can set to fulltime, parttime, contract, internship, or temporary)
$start_number = 0;  ## Start search results at this number (used for pagination)
$limit = "10";  ## Number of results per page
$fromage = "";  ## Number of days to search back (default blank = 30)
$highlght = "1";  ## Bold the keyword search terms in results (set to 0 for no bold)
$filter = "1";  ## Filters out duplicate results (set to 0 for no filter)
$latlong = "1";  ## If latlong=1, returns latitude and longitude information for each result
$co = "us";  ## Country to search jobs in
$chnl = "";  ## API Channel request.  Leave blank for none
$query = "web analytics";
$location = "55403";
$highlight = "1";
$userip = $_SERVER['REMOTE_ADDR'];  ## IP address of user
$useragent = $_SERVER['HTTP_USER_AGENT'];  ## User's browser type  
$version = "2";


$params =
       array(
                'publisher' => $publisher,
                'q' => $query,
                'l' => $location,
                'sort' => $sort,
                'radius' => $radius,
                'st' => $st,
                'jt' => $jt,
                'start' => $start_number,
                'limit' => $limit,
                'fromage' => $fromage,
                'filter' => $filter,
                'latlong' => $latlong,
                'co' => $co,
                'chnl' => $chnl,
                'userip' => $userip,
                'useragent' => $useragent,
                'v' => $version,
                 );




$url = 'http://api.indeed.com/ads/apisearch'.'?'.http_build_query($params,'', '&');




$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
$result = curl_exec($ch);
curl_close($ch);


$xml = (simplexml_load_file($url));
$xmlobj = $xml;


echo "<ol>";


foreach ($xmlobj->results->result as $job) {


    echo '<li> <strong> <a href="' . $job->url . '">' . $job->jobtitle . '</a> </strong> </li> </br>';




}


echo "</ol>";


?>
 
Last edited:
thanks allot its working great
 
How would I go about pulling more date, like description and location?
 
i got it working. thanks again.
i am still trying to figure out how to build the search query from a search box in a different page and pass it to this page to display results
 
How would I go about pulling more date, like description and location?

Demo URL updated: http://crazyflx.com/indeed/

You would do it like this:

Code:
<?php 

$publisher = "################";
$sort = "relevance";  ## Sort by "relevance" or "date"
$radius = "50";  ## Distance from search location
$st = "";  ## Site type (default blank- can set to "jobsite" or "employer")
$jt = "";  ## Job type (default blank- can set to fulltime, parttime, contract, internship, or temporary)
$start_number = 0;  ## Start search results at this number (used for pagination)
$limit = "10";  ## Number of results per page
$fromage = "";  ## Number of days to search back (default blank = 30)
$highlght = "1";  ## Bold the keyword search terms in results (set to 0 for no bold)
$filter = "1";  ## Filters out duplicate results (set to 0 for no filter)
$latlong = "1";  ## If latlong=1, returns latitude and longitude information for each result
$co = "us";  ## Country to search jobs in
$chnl = "";  ## API Channel request.  Leave blank for none
$query = "web analytics";
$location = "55403";
$highlight = "1";
$userip = $_SERVER['REMOTE_ADDR'];  ## IP address of user
$useragent = $_SERVER['HTTP_USER_AGENT'];  ## User's browser type  
$version = "2";


$params =
       array(
                'publisher' => $publisher,
                'q' => $query,
                'l' => $location,
                'sort' => $sort,
                'radius' => $radius,
                'st' => $st,
                'jt' => $jt,
                'start' => $start_number,
                'limit' => $limit,
                'fromage' => $fromage,
                'filter' => $filter,
                'latlong' => $latlong,
                'co' => $co,
                'chnl' => $chnl,
                'userip' => $userip,
                'useragent' => $useragent,
                'v' => $version,
                 );




$url = 'http://api.indeed.com/ads/apisearch'.'?'.http_build_query($params,'', '&');




$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
$result = curl_exec($ch);
curl_close($ch);


$xml = (simplexml_load_file($url));
$xmlobj = $xml;


echo "<ol>";


foreach ($xmlobj->results->result as $job) {


    $jobtitle = $job->jobtitle;
    $company = $job->company;
    $city = $job->city;
    $state = $job->state;
    $country = $job->country;
    $location = $job->formattedLocation;
    $description = $job->snippet;
    $joblink = $job->url;




    echo '<li>';
    echo '<strong> <a href="' . $joblink . '">' . $jobtitle . '</a> </strong> </br>';
    echo '<strong>Company:</strong>' . $company . '</br>';
    echo '<strong>Country:</strong>' . $country . '</br>';
    echo '<strong>City and State:</strong>' . $location . '</br>';
    echo '<strong>Description:</strong>' . $description . '</br></br>';
    echo '</li>';
}


echo "</ol>";


?>
 
Last edited:
i got it working. thanks again.
i am still trying to figure out how to build the search query from a search box in a different page and pass it to this page to display results


I've updated the demo URL again to allow for you to input your own job keyword query and then submit it and the page updates with the results. You can use the example to flesh out what you're looking to do with having the user enter search variables on one page and then pass them to the results page.

Here is the code for the demo url now (with the ability to enter your own query):

Code:
<?php 

$query = $_POST["jobquery"];


if (isset($query)) {


$publisher = "#####################";
$sort = "relevance";  ## Sort by "relevance" or "date"
$radius = "50";  ## Distance from search location
$st = "";  ## Site type (default blank- can set to "jobsite" or "employer")
$jt = "";  ## Job type (default blank- can set to fulltime, parttime, contract, internship, or temporary)
$start_number = 0;  ## Start search results at this number (used for pagination)
$limit = "10";  ## Number of results per page
$fromage = "";  ## Number of days to search back (default blank = 30)
$highlght = "1";  ## Bold the keyword search terms in results (set to 0 for no bold)
$filter = "1";  ## Filters out duplicate results (set to 0 for no filter)
$latlong = "1";  ## If latlong=1, returns latitude and longitude information for each result
$co = "us";  ## Country to search jobs in
$chnl = "";  ## API Channel request.  Leave blank for none
$query = $_POST["jobquery"];
$location = "55403";
$highlight = "1";
$userip = $_SERVER['REMOTE_ADDR'];  ## IP address of user
$useragent = $_SERVER['HTTP_USER_AGENT'];  ## User's browser type  
$version = "2";


$params =
       array(
                'publisher' => $publisher,
                'q' => $query,
                'l' => $location,
                'sort' => $sort,
                'radius' => $radius,
                'st' => $st,
                'jt' => $jt,
                'start' => $start_number,
                'limit' => $limit,
                'fromage' => $fromage,
                'filter' => $filter,
                'latlong' => $latlong,
                'co' => $co,
                'chnl' => $chnl,
                'userip' => $userip,
                'useragent' => $useragent,
                'v' => $version,
                 );




$url = 'http://api.indeed.com/ads/apisearch'.'?'.http_build_query($params,'', '&');




$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
$result = curl_exec($ch);
curl_close($ch);


$xml = (simplexml_load_file($url));
$xmlobj = $xml;


echo "<ol>";


foreach ($xmlobj->results->result as $job) {


    $jobtitle = $job->jobtitle;
    $company = $job->company;
    $city = $job->city;
    $state = $job->state;
    $country = $job->country;
    $location = $job->formattedLocation;
    $description = $job->snippet;
    $joblink = $job->url;




    echo '<li>';
    echo '<strong> <a href="' . $joblink . '">' . $jobtitle . '</a> </strong> </br>';
    echo '<strong>Company:</strong>' . $company . '</br>';
    echo '<strong>Country:</strong>' . $country . '</br>';
    echo '<strong>City and State:</strong>' . $location . '</br>';
    echo '<strong>Description:</strong>' . $description . '</br></br>';
    echo '</li>';
}


echo "</ol>";


}  else { ?>


<form action="http://crazyflx.com/indeed/" method="post">
Job Keyword (I.E. - Web Design): <input type="text" name="jobquery">
<input type="submit">
</form>


<?php } ?>
 
Back
Top