$(document).ready(function(){
$('input.phonebook_user').phonebook_user({
name: 'phonebook_user',
remote:'search.php?type=PHONEBOOK&key=%QUERY%',
limit : 10
});
});
and
<form method="post">
<table border="0">
<tr>
<td><input type="text" name="phonebook_name" placeholder="PhoneBook Name" required /></td>
</tr>
<tr>
<td><input type="text" name="phonebook_user" class="typeahead tt-query" autocomplete="off" spellcheck="false" placeholder="Type username to manage phonebook"></td>
</tr>
<tr>
<td><button type="submit" name="com_btn-phbook-create">Create PhoneBook</button></td>
</tr>
</table>
</form>
and
$TYPE=$_GET['TYPE']; // user or company
if($TYPE=="USER") {
$KEY=$_GET['key'];
$array = array();
$query=mysql_query("SELECT * FROM `users` WHERE `email` LIKE '%{$key}%'");
while($row=mysql_fetch_assoc($query))
{
$array[] = $row['email'];
}
echo json_encode($array);
}
else if($TYPE=="COMPANY") {
$KEY=$_GET['key'];
$array = array();
$query=mysql_query("SELECT * FROM `company` WHERE `company` LIKE '%{$key}%'");
while($row=mysql_fetch_assoc($query))
{
$array[] = $row['name'];
}
echo json_encode($array);
}
else if($TYPE=="PHONEBOOK") {
$KEY=$_GET['key'];
$array = array();
$query=mysql_query("SELECT * FROM `users` WHERE `username` LIKE '%{$key}%'");
while($row=mysql_fetch_assoc($query))
{
$array[] = $row['user_id'];
}
echo json_encode($array);
}
I'm trying to pull the e-mail of a user name that is getting typed and the box does not seem to show the drop down list of user names to select when you start to type in a user name. Just curious where I am going wrong with this code.
My goal is so that a user types in a user name, the drop down list shows possible matches and when you select that name, it pulls their e-mail which is then submitted to another query.
I had it working when I was just using ?key=%QUERY% in the javascript.
Am I doing my if and else statements wrong?