Autocomplete using PHP MYSQL not working
Dear Sir
refer
Auto complete not working
PHP+ JQUERY
- <?php //autocompleteindex.php
- include_once('../includes/dbconnect.php');
- $query = 'SELECT bg.name, bg.surname FROM member bg WHERE bg.name LIKE "%'.$user_input.'%"';
-
- mysql_select_db($database_DBconnect, $DBconnect);
- $Result = mysql_query($query, $DBconnect) or die(mysql_error());
- $rows = mysql_fetch_assoc($Result);
- $totalrows=mysql_num_rows($Result);
- echo "<br> Checking the Database Connection <br> ";
- echo "<br>".$query."<br> total number of rows ".$totalrows;
- echo "<br>Name ".$rows['name']."<br> Surname ".$rows['surname'];
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Autocomplete search in PHP, Mysql, Json, Autosuggestion search in PHP, Jquery UI</title>
- <meta name="description" content="This is a programming code for auto complete search in PHP, Mysql, Json or Facebook like Autosuggestion. This is a auto Complete Search tutorial developed in php, mysql and jQuery UI. Here I use Json to get response from database. After getting search data user can navigate to respective URL by href link in json."/>
- <meta name="keywords" content="Auto complete search, jQuery UI Autocomplete Search, PHP Autocomplete, Auto complete, Facebook Like auto complete, Facebook like Auto suggestion, Autosuggestion, Search, Search in PHP, autocomplete search, autocomplete search in Json, json, php, mysql, online demo, download code, rss, codeing, code, php programming, programming, php demo, jquery demo, discussdesk programming blog, discussdesk, jquery tutorial, technology"/>
-
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
- <script type="text/javascript" src="jquery-ui-1.8.2.custom.min.js"></script>
- <link href="css.css" rel="stylesheet" type="text/css" />
-
- <script type="text/javascript">
-
- $(function() {
-
- $("#dd_user_input").autocomplete({
- source: "global_search.php",
- minLength: 2,
- select: function(event, ui) {
- var getUrl = ui.item.id;
- if(getUrl != '#') {
- location.href = getUrl;
- }
- },
-
- html: true,
-
- open: function(event, ui) {
- $(".ui-autocomplete").css("z-index", 1000);
- }
- });
-
- });
- </script>
- <br /><br />- See more at: http://www.discussdesk.com/autocomplete-search-in-php-mysql-json-with-navigation.htm#sthash.TM2XnzsS.dpuf
-
- <style>
- .cnt_left {
- border: 1px solid #EEEEEE;
- padding-right: 20px;
- width: 660px;
- height:250px;
- }
- .cnt_right {
- width: 316px;
- border: 1px solid #EEEEEE;
- height: 250px;
- }
- .floatL {
- float:left;
- }
- .floatR {
- float:right;
- }
- .container{width:1000px;margin:auto;}
- .home_link{padding:10px;}
- .home_link a {
- color: #0D92E1;
- font: bold 23px arial;
- text-decoration:underline;
- }
- .main_subs{ border:1px solid #0D92E1; background:#F3F3F3; height:180px;}
- .main_subs p{padding:5px 0 0 5px; color:#0D92E1; font: bold 18px arial,tahoma;}
- .subs_email{font: normal 12px arial,tahoma; padding: 26px 0 0 35px;}
- .in_subs{padding:5px 0 0 5px; color:#0D92E1; font: bold 18px arial,tahoma;}
- .in_subs input{padding:5px 0 0 5px; color:#ccc; font: normal 15px arial,tahoma;}
- </style>
- </head>
- <body>
- <div class="container">
- <div class="cnt_left floatL">
- <div class="home_link"><a href="http://www.discussdesk.com/autocomplete-search-in-php-mysql-json-with-navigation.htm">Autocomplete search in PHP, Mysql, Json with href Link Navigation</a></div>
- <div style="border: 1px solid #EEEEEE;"></div>
-
- <form onsubmit="return false;">
- <input id="dd_user_input" type="text" class="search_form" onblur="if(this.value=='')this.value=this.defaultValue;" onfocus="if(this.value==this.defaultValue)this.value='';" value="Type your Input Here"/>
- </form>
-
- </div>
-
- <div class="cnt_right floatR">
- <div class="main_subs">
- <p>Subscribe for our Latest articles</p>
- <form onsubmit="window.open('http://feedburner.google.com/fb/a/mailverify?uri=discussdesk', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true" target="popupwindow" method="post" action="http://feedburner.google.com/fb/a/mailverify">
- <div class="in_subs"><input type="text" onblur="if(this.value=='')this.value=this.defaultValue;" onfocus="if(this.value==this.defaultValue)this.value='';" value="Enter your email address:" name="email" style="width:258px; height:30px; float:left; border: 2px double #DDDDDD;"></div>
- <input type="hidden" name="uri" value="discussdesk">
- <input type="hidden" value="en_US" name="loc">
- <input type="submit" value="Subscribe" style="font: 17px arial,tahoma;height: 39px;margin: 10px 9px 4px;width: 142px;" class="gsc-search-button"></form>
- </div>
- </div>
-
- </div>
- </div>
-
- <script type="text/javascript">
-
- var _gaq = _gaq || [];
- _gaq.push(['_setAccount', 'UA-38304687-1']);
- _gaq.push(['_trackPageview']);
-
- (function() {
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
- })();
-
- </script>
-
- </body>
- </html>
-
PHp Code (Database)
global_search.php
This code I believer is never called ..
- <?php
- /*====================== Database Connection Code Start Here =======================
-
- define ("DB_HOST", "localhost"); // set database host
- define ("DB_USER", ""); // set database user
- define ("DB_PASS",""); // set database password
- define ("DB_NAME",""); // set database name
-
- $link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
- $db = mysql_select_db(DB_NAME, $link) or die("Couldn't select database");
-
- /*====================== Database Connection Code End Here ========================== */
-
- // Here, we will get user input data and trim it, if any space in that user input data
- $user_input = trim($_REQUEST['term']);
-
- // Define two array, one is to store output data and other is for display
- $display_json = array();
- $json_arr = array();
-
-
- $user_input = preg_replace('/\s+/', ' ', $user_input);
-
- $query = 'SELECT bg.name, bg.surname FROM member bg WHERE bg.name LIKE "%'.$user_input.'%"';
-
- $recSql = mysql_query($query);
- if(mysql_num_rows($recSql)>0){
- while($recResult = mysql_fetch_assoc($recSql)) {
- // $json_arr["id"] = "http://www.discussdesk.com/".$recResult['url'].".htm";
- $json_arr["id"] = "http://www.webvikas.net.in/marathe/".$recResult['url'].".htm";
-
- $json_arr["value"] = $recResult['name'];
- $json_arr["label"] = $recResult['name'];
- array_push($display_json, $json_arr);
- }
- } else {
- $json_arr["id"] = "#";
- $json_arr["value"] = "";
- $json_arr["label"] = "No Result Found !";
- array_push($display_json, $json_arr);
- }
-
-
- $jsonWrite = json_encode($display_json); //encode that search data
- print $jsonWrite;
- ?>