mysql - Retrieve multiple values from SQL db to use in JavaScript Autocomplete -


i'm using following script input autocomplete feature. retrieve 3 columns of data mysql database. script great @ displaying 1 column, 'title', want use others, 'slug' , 'id', build clickable url each result.

what i've tried far hasn't worked. how make slug , id available use?

min_length = 2; $( document ).ready(function() {     $("#keyword").keyup(function() {         var keyword = $("#keyword").val();         if (keyword.length >= min_length) {              $.get( "auto-complete.php", { keyword: keyword } )             .done(function( data ) {                 $('#results').html('');                 var results = jquery.parsejson(data);                 $(results).each(function(key, value) {                     $('#results').append('<a href="/' + value.slug + '/' + value.id + '/"><div class="item">' + value + '</div></a>');                 })                  $('#keywordsearch').click(function() {                     var text = $(this).html();                     $('#keyword').val(text);                 })              });         } else {             $('#results').html('');         }     });      $("#keyword").blur(function(){             $("#results").hide();         })         .focus(function() {                  $("#results").show();         });  }); 

this php/sql

function serachforkeyword($keyword) {  $db = getdbconnection(); $stmt = $db->prepare("select title,id,slug `articles` title ? order title asc");  $keyword = $keyword . '%'; $stmt->bindparam(1, $keyword, pdo::param_str, 100);  $isqueryok = $stmt->execute();  $results = array();  if ($isqueryok) {   $results = $stmt->fetchall(pdo::fetch_column); } else {    trigger_error('error executing statement.', e_user_error); }  $db = null;   return $results; 

pdo::fetch_column tells driver 1 column, in case title. try different fetch mode.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -