Results 1 to 4 of 4

Thread: Help: PHP ajax search

  1. #1
    Join Date
    Apr 2008
    Posts
    240

    Help: PHP ajax search

    Hello,

    I need some information on PHP ajax search.
    If you can point me in correct direction it wil be a great help.
    I want to lean the ajax feature for PHP. How to enable it & use if for showing search results? Have a nice day.

    Thanks in advance.

  2. #2
    Join Date
    Apr 2008
    Posts
    53

    Re: Help: PHP ajax search

    The Google AJAX Search API is a Javascript library that allows you to embed Google Search in your web pages and other web applications. For Flash, and other Non-Javascript environments, the API exposes a raw RESTful interface that returns JSON encoded results that are easily processed by most languages and runtimes
    The Google AJAX Search API provides simple web objects that perform inline searches over a number of Google services (Web Search, Local Search, Video Search, Blog Search, News Search, Book Search (experimental), Image Search, and Patent Search). If your web page is designed to help users create content (e.g. message boards, blogs, etc.), the API is designed to support these activities by allowing them to copy search results directly into their messages
    http://code.google.com/apis/ajaxsearch/documentation/

    I hope this is what you need?

  3. #3
    Join Date
    Oct 2008
    Posts
    27

    Re: Help: PHP ajax search

    PHP Example - AJAX and MySQL

    The PHP page called by the JavaScript, is called "getuser.php".

    The PHP script runs an SQL query against a MySQL database, and returns the result as HTML:

    Code:
    <?php
    $q=$_GET["q"];
    
    $con = mysql_connect('localhost', 'peter', 'abc123');
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("ajax_demo", $con);
    
    $sql="SELECT * FROM user WHERE id = '".$q."'";
    
    $result = mysql_query($sql);
    
    echo "<table border='1'>
    <tr>
    <th>Firstname</th>
    <th>Lastname</th>
    <th>Age</th>
    <th>Hometown</th>
    <th>Job</th>
    </tr>";
    
    while($row = mysql_fetch_array($result))
      {
      echo "<tr>";
      echo "<td>" . $row['FirstName'] . "</td>";
      echo "<td>" . $row['LastName'] . "</td>";
      echo "<td>" . $row['Age'] . "</td>";
      echo "<td>" . $row['Hometown'] . "</td>";
      echo "<td>" . $row['Job'] . "</td>";
      echo "</tr>";
      }
    echo "</table>";
    
    mysql_close($con);
    ?>

  4. #4
    Join Date
    Oct 2008
    Posts
    101

    Re: Help: PHP ajax search

    Using the AJAX API in PHP

    Here’s a simple example of how you could use it in PHP :

    Code:
    /**
     * google_search_api()
     * Query Google AJAX Search API
     *
     * @param array $args URL arguments. For most endpoints only "q" (query) is required.  
     * @param string $referer Referer to use in the HTTP header (must be valid).
     * @param string $endpoint API endpoint. Defaults to 'web' (web search).
     * @return object or NULL on failure
     */
    function google_search_api($args, $referer = 'http://localhost/test/', $endpoint = 'web'){
    	$url = "http://ajax.googleapis.com/ajax/services/search/".$endpoint;
     
    	if ( !array_key_exists('v', $args) )
    		$args['v'] = '1.0';
     
    	$url .= '?'.http_build_query($args, '', '&');
     
    	$ch = curl_init();
    	curl_setopt($ch, CURLOPT_URL, $url);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    	// note that the referer *must* be set
    	curl_setopt($ch, CURLOPT_REFERER, $referer);
    	$body = curl_exec($ch);
    	curl_close($ch);
    	//decode and return the response
    	return json_decode($body);
    }
     
    $rez = google_search_api(array(
    		'q' => 'antique shoes',
     ));
     
    print_r($rez);

Similar Threads

  1. jQuery AJAX vs. Adobe AIR AJAX Class
    By Agaev in forum Windows Software
    Replies: 5
    Last Post: 06-07-2010, 01:59 PM
  2. Example of AJAX Live Search in PHP
    By Soumen in forum Software Development
    Replies: 4
    Last Post: 25-02-2010, 03:51 AM
  3. PHP Vs AJAX
    By Happy46 in forum Software Development
    Replies: 3
    Last Post: 03-09-2009, 07:27 PM
  4. What is AJAX in Asp.net ?
    By Braze in forum Software Development
    Replies: 5
    Last Post: 14-01-2009, 06:35 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,449,559.81319 seconds with 16 queries