nezbo Posted October 29, 2007 Share Posted October 29, 2007 Hi all I am trying to convert my code from :: echo "<tr><td align=left>Reported By : <td align=left><select NAME=RepBy>"; echo "<option value=\"\"></option>"; while($getSN2 = mysql_fetch_array($usersNames)) { echo "<option value=\"" . $getSN2['FullName'] . "\">" . $getSN2['FullName'] . "</option>"; } echo "</select>*"; to a text box like they have on face book, when you are adding a user to a list. i.e. when i start typing the name it drops down the list of people that have the same starting name. e.g. i type "s" the dropdown comes with Steven, Sam, Sian etc.. if i type "st" i only get the results Steven. Hope this makes sense... i think it will be usefull on other parts of my site as well. Cheers, Neil Quote Link to comment https://forums.phpfreaks.com/topic/75188-auto-complete-like-face-book/ Share on other sites More sharing options...
MadTechie Posted October 29, 2007 Share Posted October 29, 2007 google ajax auto suggest your find lots of examples Quote Link to comment https://forums.phpfreaks.com/topic/75188-auto-complete-like-face-book/#findComment-380249 Share on other sites More sharing options...
nezbo Posted October 29, 2007 Author Share Posted October 29, 2007 Cheers MadTechie I have never used ajax, is it complicated? i am quite a newbi... Neil google ajax auto suggest your find lots of examples Quote Link to comment https://forums.phpfreaks.com/topic/75188-auto-complete-like-face-book/#findComment-380263 Share on other sites More sharing options...
MadTechie Posted October 29, 2007 Share Posted October 29, 2007 your probably find an example that 99% of what you want.. AJAX isn't that but don't over use it.. heres a basic one i wrote awhile back.. Dynamic DropDown PHP/AJAX Quote Link to comment https://forums.phpfreaks.com/topic/75188-auto-complete-like-face-book/#findComment-380268 Share on other sites More sharing options...
nezbo Posted October 29, 2007 Author Share Posted October 29, 2007 Hi again i have got this bit of code working now nad i want to change this :: $aUsers = array( "Ädams, Egbert", "Altman, Alisha", "Archibald, Janna", "Auman, Cody", "Bagley, Sheree", "Ballou, Wilmot", "Bard, Cassian", "Bash, Latanya", "Beail, May", "Black, Lux", "Bloise, India", "Blyant, Nora", "Bollinger, Carter", "Burns, Jaycob", "Carden, Preston", "Carter, Merrilyn", "Christner, Addie", "Churchill, Mirabelle", "Conkle, Erin", "Countryman, Abner", "Courtney, Edgar", "Cowher, Antony", "Craig, Charlie", "Cram, Zacharias", "Cressman, Ted", "Crissman, Annie", "Davis, Palmer", "Downing, Casimir", "Earl, Missie", "Eckert, Janele", "Eisenman, Briar", "Fitzgerald, Love", "Fleming, Sidney", "Fuchs, Bridger", "Fulton, Rosalynne", "Fye, Webster", "Geyer, Rylan", "Greene, Charis", "Greif, Jem", "Guest, Sarahjeanne", "Harper, Phyllida", "Hildyard, Erskine", "Hoenshell, Eulalia", "Isaman, Lalo", "James, Diamond", "Jenkins, Merrill", "Jube, Bennett", "Kava, Marianne", "Kern, Linda", "Klockman, Jenifer", "Lacon, Quincy", "Laurenzi, Leland", "Leichter, Jeane", "Leslie, Kerrie", "Lester, Noah", "Llora, Roxana", "Lombardi, Polly", "Lowstetter, Louisa", "Mays, Emery", "Mccullough, Bernadine", "Mckinnon, Kristie", "Meyers, Hector", "Monahan, Penelope", "Mull, Kaelea", "Newbiggin, Osmond", "Nickolson, Alfreda", "Pawle, Jacki", "Paynter, Nerissa", "Pinney, Wilkie", "Pratt, Ricky", "Putnam, Stephanie", "Ream, Terrence", "Rumbaugh, Noelle", "Ryals, Titania", "Saylor, Lenora", "Schofield, Denice", "Schuck, John", "Scott, Clover", "Smith, Estella", "Smothers, Matthew", "Stainforth, Maurene", "Stephenson, Phillipa", "Stewart, Hyram", "Stough, Gussie", "Strickland, Temple", "Sullivan, Gertie", "Swink, Stefanie", "Tavoularis, Terance", "Taylor, Kizzy", "Thigpen, Alwyn", "Treeby, Jim", "Trevithick, Jayme", "Waldron, Ashley", "Wheeler, Bysshe", "Whishaw, Dodie", "Whitehead, Jericho", "Wilks, Debby", "Wire, Tallulah", "Woodworth, Alexandria", "Zaun, Jillie" ); to be a mysql array like this but i can't get it to work $usersNames2 = mysql_query("SELECT * FROM person"); $aUsers = array( while($getSN22 = mysql_fetch_array($usersNames2)) { $getSN22['FullName'] . ", "; } ); Please Help Neil Quote Link to comment https://forums.phpfreaks.com/topic/75188-auto-complete-like-face-book/#findComment-380309 Share on other sites More sharing options...
trq Posted October 29, 2007 Share Posted October 29, 2007 <?php if ($result = mysql_query("SELECT FullName FROM person")) { if (mysql_num_rows($result)) { $aUsers = array(); while ($row = mysql_fetch_array($result)) { $aUsers[] = $row['FullName']; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/75188-auto-complete-like-face-book/#findComment-380313 Share on other sites More sharing options...
nezbo Posted October 29, 2007 Author Share Posted October 29, 2007 Cheers Thorpe I have tryed the code you suggested and it dose not seem to work propely. this is the code of the full page if you can shed any light on why it is not working. <?php /* note: this is just a static test version using a hard-coded countries array. normally you would be populating the array out of a database the returned xml has the following structure <results> <rs>foo</rs> <rs>bar</rs> </results> */ $result = mysql_query("SELECT FullName FROM person"); $aUsers = array(); while ($row = mysql_fetch_array($result)) { $aUsers['CallID'] = $row['FullName']; } /*This is the original array code. $aUsers = array( "Ädams, Egbert", "Altman, Alisha", "Archibald, Janna", );*/ $input = strtolower( $_GET['input'] ); $len = strlen($input); $limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 0; $aResults = array(); $count = 0; if ($len) { for ($i=0;$i<count($aUsers);$i++) { // had to use utf_decode, here // not necessary if the results are coming from mysql // if (strtolower(substr(utf8_decode($aUsers[$i]),0,$len)) == $input) { $count++; $aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($aUsers[$i]), "info"=>htmlspecialchars($aUsers[$i]) ); } if ($limit && $count==$limit) break; } } header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header ("Pragma: no-cache"); // HTTP/1.0 if (isset($_REQUEST['json'])) { header("Content-Type: application/json"); echo "{\"results\": ["; $arr = array(); for ($i=0;$i<count($aResults);$i++) { $arr[] = "{\"id\": \"".$aResults[$i]['id']."\", \"value\": \"".$aResults[$i]['value']."\", \"info\": \"\"}"; } echo implode(", ", $arr); echo "]}"; } else { header("Content-Type: text/xml"); echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?><results>"; for ($i=0;$i<count($aResults);$i++) { echo "<rs id=\"".$aResults[$i]['id']."\" info=\"".$aResults[$i]['info']."\">".$aResults[$i]['value']."</rs>"; } echo "</results>"; } ?> Cheers Neil <?php if ($result = mysql_query("SELECT FullName FROM person")) { if (mysql_num_rows($result)) { $aUsers = array(); while ($row = mysql_fetch_array($result)) { $aUsers[] = $row['FullName']; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/75188-auto-complete-like-face-book/#findComment-380351 Share on other sites More sharing options...
trq Posted October 29, 2007 Share Posted October 29, 2007 Why change... $aUsers[] = $row['FullName']; to... $aUsers['CallID'] = $row['FullName']; ? This will only ever store the last user. Quote Link to comment https://forums.phpfreaks.com/topic/75188-auto-complete-like-face-book/#findComment-380354 Share on other sites More sharing options...
nezbo Posted October 29, 2007 Author Share Posted October 29, 2007 sorry i ment to put this $row['CallID'] so i could use the CallID columb in the database so the id reflects the user id... but i have tryed removing that and it still dose'nt work that code now reads again.. $aUsers[] = $row['FullName']; Why change... $aUsers[] = $row['FullName']; to... $aUsers['CallID'] = $row['FullName']; ? This will only ever store the last user. Quote Link to comment https://forums.phpfreaks.com/topic/75188-auto-complete-like-face-book/#findComment-380445 Share on other sites More sharing options...
nezbo Posted October 30, 2007 Author Share Posted October 30, 2007 Hi all I am still having problems with this code, i am not to sure how to get it working... Here is the code i have and the array works fine on its own but when i put it in to the code that creats the autodrop down it dosent work :: $result = mysql_query("SELECT * FROM person"); $aUsers = array(); while ($row = mysql_fetch_array($result)) { $aUsers[] = $row['FullName']; } This is the original code that works in the drop down... /* $aUsers = array( "Ädams, Egbert", "Altman, Alisha", "Archibald, Janna", ); */ i have just seen this and i am not to sure what it means ? /* note: this is just a static test version using a hard-coded countries array. normally you would be populating the array out of a database the returned xml has the following structure <results> <rs>foo</rs> <rs>bar</rs> </results> */ Also the site i have got the autocolplete code from is :: http://www.brandspankingnew.net/archive/2007/02/ajax_auto_suggest_v2.html Please Help Quote Link to comment https://forums.phpfreaks.com/topic/75188-auto-complete-like-face-book/#findComment-381010 Share on other sites More sharing options...
MadTechie Posted October 30, 2007 Share Posted October 30, 2007 check your xml output.. is it correct/as expected ? Quote Link to comment https://forums.phpfreaks.com/topic/75188-auto-complete-like-face-book/#findComment-381078 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.