Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I've been trying for sometime to build a live search. The goal is to display a name (ex. John Doe), an img, and to append a username to the href of whatever the result is. All of these are stored in a database, and I'm using PHP. I've built something in PHP that does this, but it queries the database everytime, and is obviously very slow. I want something to go faster.

Right now, I am using jQuery autocomplete. I have a function written in php to pull all the names out of the database. Then I echo it out in JSON and have jQuery search the contents of that JSON. That IS WORKING. I can search for a name just fine. However, when a name comes up, I want it to link to someones profile. Here is the jquery I have written. Again, it is displaying the names perfectly, however I want to add a link to each name autocomplete finds.

$(function() {
var availableTags = <?php include("../includes/functions.php"); $names = search(); echo       json_encode($names);?>;
$( "#search" ).autocomplete({
  source: availableTags
});
});

Here is the PHP function that pulls the names:

function search() {
$global connection;
$sql = 'SELECT display_name FROM users';
$query = mysql_query($sql,$connection);
while ($result = mysql_fetch_assoc($query)) {
  $display_name = $result['display_name'];
  $names[] = $display_name;
}
return $names;
}

I obviously have to change my query to pull the username as well as pic_file. I want the link to go to profile.php?username=(the username of the given display_name). How to i append a link to each of the results that come up for autocomplete in the jQuery I have written? If not possible, is there something better I could possibly be using than autocomplete? Thank you so much in advance.

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.