Jump to content

Auto complete search (from database)


spluskhan

Recommended Posts

hello all of you.

 

i have database name Products

id

pr_name

good

poor

faulty

 

i need auto complete search that they suggest (pr_name) from my phpmyadmin database.

 

this is my search code:

 

<div id="wb_Form2" style="position:absolute;width:483px;height:112px;">
<form name="search" method="get" action="db1.php" id="Form2" onsubmit="return Validatesearch(this)">
<input type="text" id="Editbox8" style="position:absolute;left:11px;top:17px;width:456px;height:38px;line-height:38px;z-index:2;" name="query" value="" autocomplete="off" input type="text" name="query">
<input type="submit" id="Button3" name="" value="Add" style="position:absolute;left:192px;top:71px;width:96px;height:37px;z-index:3;">
</form>
</div>

 

 

and this is my search code:

<html>
<body>
<head>
<font size="3"><strong>
<?php // Connects to your Database 
    mysql_connect("host", "user", "pass") or die(mysql_error());
    mysql_select_db("table") or die(mysql_error());
$q = mysql_real_escape_string($_GET['query']);
$data = mysql_query("SELECT * FROM Products where name LIKE '%$q%'")
    or die(mysql_error()); 
    while($info = mysql_fetch_array( $data ))
    { 
echo "Product Name: $info[name]<br>";
echo "Good Price: $info[good]<br>";
echo "Poor Price: $info[poor]<br>";
echo "Faculty Price: $info[faulty]<br><br>";
    } 
    ?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/275583-auto-complete-search-from-database/
Share on other sites

Try combining some of the code from the previous link with this one: http://w3schools.com/php/php_ajax_database.asp - use the input from the first and cut out the xml and in the second one cut out the options and keep the stuff for the database and then manipulate it to your need

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.