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.
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.
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?
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); ?>
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);
Bookmarks