PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 17th, 2013, 01:07 AM
anikn anikn is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 anikn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #2  
Old January 17th, 2013, 07:16 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,879 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 2 Days 1 h 38 m 19 sec
Reputation Power: 581
1) Please enclose your code in [ PHP ] tags. See the sticky at the top of this forum.
2) To return multiple values, use an array, although I don't see any PHP functions that return anything.
PHP Code:
 $retval[]=$value1;
$retval[]=$value2;
return(
$retval); 

3) Do not use the deprecated MySQL extensions, switch to PDO.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #3  
Old January 17th, 2013, 07:30 AM
anikn anikn is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 anikn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 12 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
1) Please enclose your code in [ PHP ] tags. See the sticky at the top of this forum.
2) To return multiple values, use an array, although I don't see any PHP functions that return anything.
PHP Code:
 $retval[]=$value1;
$retval[]=$value2;
return(
$retval); 

3) Do not use the deprecated MySQL extensions, switch to PDO.


The 9th line from last echo($row['0']) ."\n"; ?> inside a for loop adds the suppname to the list which will get displayed in the dataentry screen. (customer.php)

If you have any other method of coding Ajax that returns 2 values, pls help me.

Reply With Quote
  #4  
Old January 17th, 2013, 07:47 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,879 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 2 Days 1 h 38 m 19 sec
Reputation Power: 581
This is really a Javascript/Ajax question. You can have it moved to that forum by clicking on the red triangle in the upper right.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - Ajax Autocomplete textbox

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap