Creating custom autosuggest query
-
First of all, I tried to post in WP-Advanced but see that only moderators can post there, so I have added a modlook tag.
I am trying to create an autosuggest as in this post (https://www.htmlblog.us/jquery-autocomplete) which searches one of my own tables. I am using the Allow PHP in Posts and Pages plugin.
I can get the form to work
echo "<html>"; echo "<head>"; echo "<script type='text/javascript' src='jquery/js/jquery-1.4.2.min.js'></script>"; echo "<script type='text/javascript' src='jquery/js/jquery-ui-1.8.2.custom.min.js'></script>"; echo "<script type='text/javascript'> jQuery(document).ready(function(){ $('#zipsearch').autocomplete({source:'/thegrapevine/?page_id=219', minLength:2}); }); </script>"; echo "<link rel='stylesheet' href='jquery/css/smoothness/jquery-ui-1.8.2.custom.css' />"; echo "<style type='text/css'><!-- /* style the auto-complete response */ li.ui-menu-item { font-size:12px !important; } --></style>"; echo "</head>"; echo "<body>"; echo "<form onsubmit='return false;'>Enter a Zipcode:<input id='zipsearch' type='text' />"; echo "</form>"; echo "</body>"; echo "</html>";
but the call to the php script that searches the table is not working.
$rs = mysql_query('select zip, city, state from zipcode where zip like "'. mysql_real_escape_string($_REQUEST['term']) .'%" order by zip asc limit 0,10', $dblink); $data = array(); if ( $rs && mysql_num_rows($rs) ) { while( $row = mysql_fetch_array($rs, MYSQL_ASSOC) ) { $data[] = array( 'label' => $row['zip'] .', '. $row['city'] .' '. $row['state'] , 'value' => $row['zip'] ); } } echo json_encode($data); flush();
I have tried placing the code in a page and as a template but neither work.
As anyone done anything like this?
Thanks
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Creating custom autosuggest query’ is closed to new replies.