Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6234057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:24:48+00:00 2026-05-24T10:24:48+00:00

I have a semi-functioning site. I have a non functional search bar. I want

  • 0

I have a semi-functioning site. I have a non functional search bar. I want the user to be able to type in a person’s name. Then I want the search bar to return the person’s name and picture on onkeydown(). Basically like Facebook.

This will need the XHTML/CSS similar to a drop down menu, but with a query to the mysql table. Facebook queries both the first name and last name field which explains why they don’t combine the two like twitter does. I only have a full name inserted so that makes that easier. I’ll send each letter and match against the full_name mysql column. How do you write the regular expressions to do this or more high level – how do you write the function to do this?

PHP – Pseudo code

function match()
  {
  //  Run Query
  //  Return list(full_name,picture)
  //  If less then 5
         Modify up query to obtain 5
         Embedded if (special case less then 5 available - new site)
           Send
      If more then 5
         Modify down query to obtain 5
      Elseif ==5
         Send

  }

CSS/XHTML/Javascript

function display()
  {
  // Display list - set max returns (5)
  }
  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:24:49+00:00Added an answer on May 24, 2026 at 10:24 am

    Check out the jQueryUI Autocomplete feature, particularly the Remote Datasource and Custom Data and Display examples.

    What you’ll want on the PHP side is to

    1. Query the database based on supplied search data
    2. Build an array of matching entries
    3. Display that array as JSON data using json_encode()

    Update

    This is modified from my Facebook friend autocomplete selector.

    Here’s the core of the JavaScript

    jQuery(function($) {
        var field = $('#friend-name'); // text field for name
        var idField = $('#friend-id'); // hidden field for ID
        field.autocomplete({
            minLength: 3,
            width: 240,
            source: 'search.php',
            change: function(event, ui) {
                idField.val(ui.item != null ? ui.item.id : '');
                return true;
            }
        }).data('autocomplete')._renderItem = function(ul, item) {
            var img = '<img src="' + item.picture + '">';
            return $('<li>')
                   .data('item.autocomplete', item)
                   .append('<a>' + item.label + img + '</a>')
                   .appendTo(ul);
        };
    });
    

    The PHP part to search based on parameters would look something like this

    // search.php
    
    // assuming PDO connection already made in $db
    $stmt = $db->prepare('SELECT `id`, `name`, `picture` FROM `Person` WHERE LOWER(`name`) LIKE ?');
    $stmt->execute(array(
        strtolower($_GET['term'] . '%')
    ));
    $people = array();
    while($person = $stmt->fetch(PDO::FETCH_ASSOC)) {
        $people[] = array(
            'label'   => $person['name'],
            'value'   => $person['name'],
            'picture' => $person['picture'],
            'id'      => $person['id']
        );
    }
    echo json_encode($people);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a semi-weird issue for our site. Consistently, from 1 anonymous* user the
I have a dilema, I want to present to the user a semi-transparent view.
I'm building a semi-elaborate RadGrid where within my NestedViewTemplate I want to have a
I have a semi-complicated problem and hoping that someone here will be able to
I have a navigation bar with a semi-transparent background but the navigation links are
I have used XDebug semi-sucessfully with PhpStorm and Mamp, but now I want to
I have a semi-large web application that we run locally and I need to
Okay so i have a semi weridish problem with re.sub. Take the following code:
I have an entry.rb model and I'm trying to make a semi-complicated validation. I
I have an image. Over it I draw a semi transparent polygon. Over the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.