0

Hello Every One.

i have a database name products
id
Pr_name
price etc

I want auto complete script that they retrive product name from (Pr_name).
i want that my search enging display auto name from my database.

Edited by spluskhan: spelling

5
Contributors
29
Replies
131
Views
4 Years
Discussion Span
Last Post by spluskhan
Featured Replies
  • 1
    diafol 3,720   4 Years Ago

    http://www.jqueryautocomplete.com/jquery-autocomplete-php-mysql-json-example.html http://beski.wordpress.com/2009/11/20/jquery-php-mysql-ajax-autocomplete/ http://www.simonbattersby.com/blog/jquery-ui-autocomplete-with-a-remote-database-and-php/ http://devmanuals.com/tutorials/php/autocomplete.html Read More

0

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:18;" 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:19;">
</form>
</div>
0

So what do you want? You want us to write code for you? Where's your code?

This is my Search Code:

That's not code, it's markup, and use CSS if possible instead of inline styling. If you post your php code, we can have a look at it.

0

Thats my search code.
i have one other code which is for print search data.

0

Like I said, that's markup, not 'code'. It doesn't actually do anything, just display a searchbox/button. I'm referring to your php/mysql code. Where's that? That's what we need to see in order to help you with any difficulties that you may be experiencing.

So, post your code...

0

Well, this is a help forum, but it's mainly to help you with your own code. It's not expected of contributors to write code from scratch.

How about you look at the php.net manual or look at some online php tutorials to get started? There are hundreds of tutes out there.

here's a starter for mysqli to make a db connection: http://uk3.php.net/manual/en/mysqli.construct.php

0

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>";
    } 
    ?>
0

does the above code give you results..?
i mean does it output product name, good price, ... etc?

if not could it be mysql_select_db("table") or die(mysql_error());
you should have database name where you written table?

Edited by t_thakar: spelling mistake

0

it didn't show anything

What didn't? The tutorials were not whta you wanted or you couldn't get the scripts to work?
Unless you post your updated code with errors/problems, we don't know what you're trying.

0

Thgis is Scripts:

autocompletemain.php

<?php
$host="host.com"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name


    $con = mysql_connect($host,$username,$password)   or die(mysql_error());
    mysql_select_db($db_name, $con)  or die(mysql_error());

$q = strtolower($_GET["q"]);
if (!$q) return;

$sql = "select Products name as name from name where name LIKE '%$q%'";
$rsd = mysql_query($sql);
while($rs = mysql_fetch_array($rsd)) {
    $cname = $rs['name'];
    echo "$cname\n";
}
?>

And Form

<?php
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

<title>jQuery Autocomplete Plugin</title>
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type='text/javascript' src="js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />

<script type="text/javascript">
$().ready(function() {
    $("#course").autocomplete("autoCompleteMain.php", {
        width: 260,
        matchContains: true,
        //mustMatch: true,
        //minChars: 0,
        //multiple: true,
        //highlight: false,
        //multipleSeparator: ",",
        selectFirst: false
    });
});
</script>
</head>
<body>
<h2 id="banner">Autocomplete using jQuery, Ajax, PHP</h1>
<div id="content">
    <form autocomplete="off">
        <p>
            Enter Language Name <label>:</label>
            <input type="text" name="name" id="name" />
        </p>
        <input type="submit" value="Submit" />
    </form>
</div>
</body>
</html>
0

Have you tried out a dummy page with this script, e.g.

In your php page, just have:

<?php

echo "boo\nfoo\nbar";

?>

Also, look at the console to see if you have any js issues. If using Chrome, this can be found with right-click > 'Inspect element' > 'Console'

0

OK you're problem seems to be the php/mysql then. Fix it and it should work.

0

so if autocomplete js is working with hard coded php and your php/mysql is working (tested by you), sorry I'm lost, can't see any reason why your code won't work.

0
  1. there is difference in the name of the file.While calling "M" is capital of autocompletemain.php

    $("#course").autocomplete("autoCompleteMain.php", {
    
  2. 2nd problem is of the id "course" that you are using

    Instead of "course" ,it should be the id of textbox i.e,"name".

    Replace this,

     $("#course").autocomplete("autoCompleteMain.php", {
    

    with

     $("#name").autocomplete("autoCompleteMain.php", {
    

    Replace the two problems,and hope autocomplete is working.If still there is problem do ask along with the error.

Also keep note of first point.Either change file name or change it here.

Edited by IIM

0

thankx for your suggestions prob was in database. but here is some ting that you gyz provide help.

i hhave my own form this is code: (searchform.php)

<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:4;" 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:5;">
</form>
</div>

And this is jave script form (javascript.php)

<?php
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

<title>Autocomplete</title>
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type='text/javascript' src="js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />

<script type="text/javascript">
$().ready(function() {
    $("#name").autocomplete("autoCompleteMain.php", {
        width: 260,
        matchContains: true,
        //mustMatch: true,
        //minChars: 0,
        //multiple: true,
        //highlight: false,
        //multipleSeparator: ",",
        selectFirst: false
    });
});
</script>
</head>
<body>
<h2 id="banner">Autocomplete</h1>
<div id="content">
    <form autocomplete="off">
        <p>
            Enter Product Name <label>:</label>
            <input type="text" name="name" id="name" />
        </p>
        <input type="submit" value="Submit" />
    </form>
</div>
</body>
</html>

My Prob is i want to implement my autosearch java function into my own form code (searchform.php)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.