hey guys,

I'm trying to create a search engine that uses an API from the yellow pages, I have read and watched several tutorials on how to create a form and run a search using php.

Sensis and Yellowpages recently released an API which is pretty cool and might have potential

I decided to see if i could create a search engine and then display the results as a hobby and learning project.

I am trying to use example code from the website of the API, I am having trouble figuring out what code to change in order to be able to conduct my own search. As you can see in the code below, the search is currently pre-defined to hairdresser, I have tried using a few different things like $results = search (" ", $query) or $results = search ($_GET ['search']) to connect the API to my search form, with no success.

the most help so far, and the closest thing i could find was this youtube video - http://youtu.be/PdM2ZIG9yR0

The API Documentation and the Example come from - http://developers.sensis.com.au/docs/examples/PHP

Please view my code below and help me figure out what i need to do, so i can connect my search form with the API search endpoint thingy.

This thing is kicking my *** lol, any help would be good.


PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Yolo - Results</title>

<link href="stylesheets/style-search.css" rel="stylesheet" type="text/css" />

<div class="search_container">
  <h1> <img src="images/search-image.png" alt="search_icon" width="27" height="27"/>Yolo </h1>
    <form id="form1" name="form1" method="get" action="./search.php">
        <input name="Search" type="text" id="Search" value='<?php echo $_GET ['Search']; ?>' onfocus="this.value=''" size="50"/>
        <input name="Submit" type="submit" class="nav" id="Submit" onclick="/search.php" value="Search" size="30"/>
        <br />
<div class="search_results_container">
    <hr />
  <h3> Results for: <?php echo $_GET ['Search']; ?> <br />
    <hr />
    <h3><br />

function search() {

$search $_GET['search'];
$terms explode(" "$search);
$query "SELECT * FROM search WHERE ";
        foreach (
$terms as $each) {
            if (
$a == a
$query .= "keywords LIKE '%$each%' ";
$query .= "OR keywords LIKE '%$each%' ";

# put your API key here

# location of the search API endpoint
$endpoint "http://api.sensis.com.au/ob-20110511/test/search";

# construct a URL with the query string, escaping any special characters.
$url $endpoint "?key=" $apikey 
"&query=" urlencode($query) . 
"&location=" urlencode($location);

# call the endpoint
$response file_get_contents($url); 
# ensure we actually got a response back         
if (!$response) {
            throw new 
Exception("Error calling API ($http_response_header[0])");

# convert the response message to an associative array
$result json_decode($responsetrue);
# grab the response code
$code $result["code"];

# ensure successful status code
if ($code == 200) { # success
return $result
        } else if (
$code == 206) { # spell-checker was run
echo "Note: " $result["message"] . "\n";
        } else {
            throw new 
Exception("API returned error: " 
$result["message"] . ", code: " $result["code"]);


example() {

        try {

# perform a search for 'hairdresser' 
$results search($query);
"Total results found: " $results["totalResults"] . "\n";

# the results member is an array containing each listings as a nested associative array
foreach ($results["results"] as &$result) {
$result["name"] . " (" $result["primaryAddress"]["addressLine"] . ")\n";
        } catch (
Exception $e) {
# something bad happened
echo "Internal error: $e\n";




    <div class="social_icons_container">
    <hr />
<div class="footer">
<p>copyright 2013 - contact - about - legal</p>