I´m trying to develope an autocomplete script using jQuery, now I´m in the last step. I need to make a php page to call database, but the problem is I don´t know how the data(to be called to autocomplete)should lok like. I know the script using something call "jsonp"
Here is the important lines that i want to show you, and my question is: How to build php code to make corectly data for this ?
function e(){f=-1;$("#ac_results").css("display", "none")}function g(l,m){$.trim(p.val().toLowerCase())===l.toLowerCase()&&$.ajax({dataType:"jsonp",url:ac_server+"/"+encodeURIComponent(l)+"?callback=?&t="+m,success:function(k){var r=parseInt(k.t); if(r>=s){s=r;t[l]=k.r;++w;b(k.r,l)}}})}var f=-1,h=0,n=i,s=0,t=[],w=0,p;return{bind:function(){p=$(a);if(typeof ac_server==="undefined")return c();p.attr("autocomplete","off"); p.bind("keyup",function(l){var m=(new Date).getTime(),k=$.trim($(this).val()); k=k.toLowerCase();if(!(l.keyCode in[40,38,13,27]||!n))if(k.length> 0)t[k]!==undefined?b(t[k],k):setTimeout(function(){g(k,m)},0);else e()});$(document).bind("keyup",function(l){if(l.keyCode===27)e();else if(l.keyCode!=undefined){$(".ac_active").attr("class","ac_inactive");switch(l.keyCode){case 40:if(f==-1)f=0;else if(++f>=h)f=0;$("#ac_opt_"+f).attr("class","ac_active");d($("#ac_opt_"+f));break;case 38:if(f==-1)f=h-1;else if(--f<0)f=h-1;$("#ac_opt_"+f).attr("class","ac_active");d($("#ac_opt_"+f));break;case 13:if(f!=-1){l=$("#ac_opt_"+f);l.length&&d(l,1)}else e()}}}); $("body").bind("click.autocompleter",function(){$(this).attr("id").indexOf("ac_")===-1&&e()});return this},fa:c}}("#ac_q"); (function(a){a.fn.U=function(b){var c=this;b=a.extend({A:"tactive",p:"tnactive",aa:".toptions",B:0,z:"href"},b||{});a(this).each(function(){var d=a(this).find(b.aa).children(),e;d.each(function(g){a(this).addClass(b.p);a(this).click(function(f){f.preventDefault();a(this).addClass(b.p);f=c.find(a(this).attr(b.z));if(f.length===0)throw"Could not find matching tab content for id: "+a(this).attr(b.z);e.removeClass(b.A).addClass(b.p);a(e.attr(b.z)).hide();a(this).removeClass(b.p).addClass(b.A);f.show(); e=a(this)}); if(g===b.B||g===0&&d.length-1<b.B){e=a(this); a(this).trigger("click")}})})}})(jQuery);
thanks for further help
More explaination: I really don´t know what is the variable i should make and what it should be look like. but here is something I tried but still not work.
//db connection detils $host = "localhost";
$user = "root"; $password = "yourpasswordhere"; $database = "comments";
//make connection
$server = mysql_connect($host, $user, $password); $connection = mysqlselectdb($database, $server);
//query the database
$query = mysql_query("SELECT * FROM comments");
//loop through and return results
for ($x = 0, $numrows = mysqlnumrows($query); $x < $numrows; $x++) { $row = mysqlfetchassoc($query);
$comments[$x] = array("name" => $row["name"], "comment" => $row["comment"]); } //echo JSON to page $response = $_GET["jsoncallback"] . "(" . json_encode($comments) . ")"; echo $response;
Please go through the following link:
http://www.roseindia.net/tutorial/ajax/jquery/autocomplete.html
Hi, thanks, it´s not what I´m looking for. This script that I post is a perfect script. Can be used like perfectly search engine like google.
I have got it from a web site, but what I have to do is finding the php code to give the correctly data.
It´s hard work i know, but i i found it, will be perfect.
I mean if i found it, will be perfect, hehe but i not found it yet.