Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 10-07-2009
Member
 
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.
Reply With Quote
  #2  
Old 10-07-2009
Member
 
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?
Reply With Quote
  #3  
Old 10-07-2009
Member
 
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);
?>
Reply With Quote
  #4  
Old 10-07-2009
Member
 
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);
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Help: PHP ajax search"
Thread Thread Starter Forum Replies Last Post
jQuery AJAX vs. Adobe AIR AJAX Class Agaev Windows Software 5 06-07-2010 01:59 PM
Example of AJAX Live Search in PHP Soumen Software Development 4 25-02-2010 03:51 AM
PHP Vs AJAX Happy46 Software Development 3 03-09-2009 07:27 PM
What is AJAX in Asp.net ? Braze Software Development 5 14-01-2009 06:35 PM


All times are GMT +5.5. The time now is 10:03 PM.