
January 17th, 2013, 01:07 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 2
Time spent in forums: 17 m 12 sec
Reputation Power: 0
|
|
|
PHP-General - Ajax Autocomplete textbox
I am coding a PHP program to make a list of items (e.g.,customer name) just below the textbox.
My code for data entry is (customer.php)
<?php
/**
* @author
* @copyright 2012
*/
?>
<head>
<script>
function ClearScreen()
{
document.f1.storename.focus();
}
function confirmation(url)
{
window.location=url;
}
</script>
<link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.autocomplete.js"></script>
<script>
$(document).ready(function(){
$("#suppname").autocomplete("autocomplete.php?from=supplier", {
selectFirst: true
});
});
</script>
</head>
<form name="f1" method="post" action="customeradd.php">
<table>
<tr>
<td>Name</td>
<td><input type="text" name="suppname" id="suppname" size="20" /></td>
<td><input type="text" name="suppid" id="suppid" /></td>
</tr>
<tr>
<td>Address</td>
<td><textarea name="address" rows="4" cols="50"></textarea> </td>
</tr>
<tr>
<td>Phone</td>
<td><input type="text" name="phone" id="phone" size="20" /></td>
</tr>
<tr>
<td>Type</td>
<td><select name="type">
<option value="Customer">Customer</option>
<option value="Supplier">Supplier</option>
</select></td>
</tr>
<tr>
<td>Credit limit</td>
<td><input type="text" name="credit" id="credit" size="20" /></td>
</tr>
<tr>
<td>Notes</td>
<td><textarea name="notes" rows="4" cols="50"></textarea></td>
</tr>
</table><table>
<tr>
<td><input type="button" value="Save" onclick="confirmation('storeadd.php?mode=1&storename='+storename.value)" /></td>
<td><input type="button" value="Delete" onclick="deletestore.php?storeid=''" /></td>
</tr>
</table>
<div id="txtHint"></div>
</form>
<?php
function loadvalues()
{
echo "<script>javascript:alert('hello');</script>";
}
?>
The code to fetch the desired list is (autocomplete.php) is
<?php
$q=$_GET['q'];
$from=$_REQUEST['from'];
$my_data=mysql_real_escape_string($q);
include("connect.php");
$database="stockdata";
mysql_select_db ($database, $link);
if($from=="store")
$sql="SELECT storename,storeid FROM store WHERE storename LIKE '%$my_data%' ORDER BY storename";
if($from=="supplier")
$sql="SELECT suppname,suppid FROM supplier WHERE suppname LIKE '%$my_data%' ORDER BY suppname";
$result=mysql_query($sql);
$num_rows = mysql_num_rows($result);
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
if($result)
{
$row = mysql_fetch_row($result);
for ($i=0;$i < $num_rows ; $i++)
{
echo($row['0']) ."\n"; ?>
<input type="hidden" name="suppid" id="suppid" VALUE="<?php echo($row['1'])?>" />
<?PHP //echo $sql;
//$answer = array ($row['1'] );
$row = mysql_fetch_row($result);
}
}
//var_dump($answer);
?>
It is working fine. But I want this code to return 2 values (suppname and suppid) to the calling code. How is it possible?
|