2011-11-07

autocomplete jquery for female name

gw penasaran ama google dan tag di blogger ini.. ketika gw ketik A maka akan keluar pilihan yg ada huruf Anya.. saat ketemu dan intip script orang.. kok kayaknya boros banget ya..
semua pilihan katanya ditulis dalam javascript!! lalu gw kepikiran gimana cara menanganinya?
This begin when I currious about how google manage to take our search. When I type One.. then piece.. etc will show up!!

but when I see the code (from jquery and other tutorial site).. the script is too long to learn!? suddenly I know how to deal with it!!
From this point.. I will give only english tutorial

start with download this
http://www.mediafire.com/?ud8xjfi2m6n955d then follow my step

  1. extract to htdocs. You should make new folder and extract inside that folder. My HTDOCS is in C:\PHP
  2. then open you phpmyadmin
  3. create database test (if different, you should edit the script later)
  4. import test.sql into the database
  5. rename 046-auto2.php into another name you like. But don't rename  now.. 
  6. edit 047-scriptAuto.php ; change this line  if your database setting is not open (root with no password?)
    $con=mysql_connect('localhost','root',''); 
  7. run 046-auto2.php
  8. try type inside the box
  9. you will have female list name
this script not make your script/server overload!! 

this is the main core of the script
<div class="demo"> 
<div class="ui-widget"> 
<label for="tags">Female Name: </label> 
<input id="tags" /> 
</div> 
<script> 
$("#tags").keyup(function() { 
var val1 = "047-scriptAuto.php?s="+$(this).val(); 
$("#tes").load(val1); 
}); 
</script> 
<div id='tes'> </div> 
</div> 

if you see.. my script called 2nd script. inside the 2nd script lies data that will showup!

When you type text inside the textbox.. it will call 2nd script with GET variable using S.. this GET variable will process in the 2nd script
<script> 
$(function() { 
var availableTags = [ 
<? 
$con=mysql_connect('localhost','root',''); 
$cari=trim($_GET[s]); 
$r=mysql_db_query('test',"select * from name where name like '%$cari%' limit 0,10"); 
while($row=mysql_fetch_array($r)) 
{ 
$s.='"'.$row[0].'", '; 
} 
echo $s; 
?> 
]; 
$( "#tags" ).autocomplete({ 
source: availableTags 
}); 
}); 
</script> 
the php code will give you all data you will need.

1 komentar:

writer mengatakan...

http://www.mediafire.com/?3cyhk3eiabzb7ty
link yg baru