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 6042543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:48:09+00:00 2026-05-23T06:48:09+00:00

Friends text box with autocomplete script (which supports multiple word completion from userstable fullname

  • 0

Friends text box with autocomplete script (which supports multiple word completion from userstable “fullname” column) in registration form. Now Question 1: How to get names array from text input field and find id’s of theese fulnames with php? Question 2: How registration form will put theese id’s to second (friends) table, if new users id unknown during registration?
For example, if visitor writes “Tu” script finds from users table “Tural Teyyuboglu”, completes it, adds comma, user can add as much he wants user names. Every time script works. I want to get this usernames seperated by comma to php array, search theese usernames one by one for id’s and add to friends table. But second wuestion occurs? But how registration form will put theese id’s to second (friends) table, if new users id unknown during registration?

Sorry for my bad english. My idea: I have a database of users, each user has an autoincremented id number field, and various other fields with their details on. I would like to store within the user record a field with an array of friends. I would like the most efficient way to store and be able to search each users ‘friend id array’ field and list the friends ids per user search. assuming at some point there could be a million users of which each has a million ‘friend ids’ in their array, I dont think having them comma seperated would be efficient, any solutions? could it be stored in a blob and searched bitwise? (e.g a bit per person, so a 1k blob can store up to a possible 1024 friend combinations) I think another table is the best solution. It is a many-to-many relationship, I’ve built a separate table for user friends: usrfrnd_tbl with columns UserFriendID (unique key), UserID, FriendID In i applied Jquery autocomplete to friends field of registration form: When visitor types name of existing user to this input field, first of all, script searches for name existence, completes it (if exists), adds comma. User can type second, third… existing usernames to this field, and everytime script will auto complete. Now i want to create php file that will search for id’s of these usernames, create array of id’s, add it to table “usrfrnd_tbl” new users “FriendID” field in db table. Question: 1. How to do it? Now, how to fetch array of id’s of written names, and put to “friends” field of usr_table after submission of registration form? 2. I need only id of written name,and fullname. I don’t need value.How can i delete it from jquery code?

HTML

<form action="index.php" method="post">      
<input class="std" type="text" name="friends" id="friends"/>
<input type="submit" name="submit">
</form>

Jquery

$(function() {
    function split( val ) {
        return val.split( /,\s*/ );
    }
    function extractLast( term ) {
        return split( term ).pop();
    }

    $( "#friends" )
        // don't navigate away from the field on tab when selecting an item
        .bind( "keydown", function( event ) {
            if ( event.keyCode === $.ui.keyCode.TAB &&
                    $( this ).data( "autocomplete" ).menu.active ) {
                event.preventDefault();
            }
        })
        .autocomplete({
            source: function( request, response ) {
                $.getJSON( "search.php", {
                    term: extractLast( request.term )
                }, response );
            },
            search: function() {
                // custom minLength
                var term = extractLast( this.value );
                if ( term.length < 2 ) {
                    return false;
                }
            },
            focus: function() {
                // prevent value inserted on focus
                return false;
            },
            select: function( event, ui ) {
                var terms = split( this.value );
                // remove the current input
                terms.pop();
                // add the selected item
                terms.push( ui.item.value );
                // add placeholder to get the comma-and-space at the end
                terms.push( "" );
                this.value = terms.join( ", " );
                return false;
            }
        });
});

search.php

$db = new mysqli('localhost', 'user' ,'pass', 'db') or die(mysqli_errno());
$q = strtolower($_GET["term"]);
if (!$q) return;
$query =  $db->query("select id, fullname from usr_table where fullname like '$q%'")  or die(mysqli_errno());
$results = array();
while ($row = mysqli_fetch_array($query)) {$results[] = array ( "id" => $row[0] , "label" => $row[1], "value" => $row[1] );}
echo json_encode($results);
  • 1 1 Answer
  • 0 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-23T06:48:09+00:00Added an answer on May 23, 2026 at 6:48 am
    $usr_fullname = mysql_real_escape_string($_GET['usr_fullname']);
    // other user information here
    
    $friend_str = mysql_real_escape_string($_GET['friend_str']);
    
    $sql = "
    INSERT INTO usr_table 
        (`fullname`, `etc`) 
    VALUES 
        ('$usr_fullname', etc)
    ";
    
    $result = mysql_query($sql) or die(mysql_error());
    
    $new_user_id = mysql_insert_id($result);
    
    $friend_arr = explode(',', $friend_str);
    
    foreach($friend_arr as $friend_name) {
        $friend_name = trim($friend_name);
    
        if (empty($friend_name)) {
            continue;
        }
    
        $sql = "
        SELECT id
        FROM usr_table
            WHERE `fullname` = '$friend_name'
        LIMIT 1
        ";
    
        $result = mysql_query($sql);
    
        if (!$result) {
            echo "$sql failed " . mysql_error();
            exit;
        }
        if (mysql_num_rows($result) == 0) {
            continue; // this person does not exist
        }
    
        $data = mysql_fetch_array($result);
        $friend_id = $data['id'];
    
        $sql = "
        INSERT INTO usrfrnd_table 
            (`user_id`, `friend_id`)
        VALUES
            ('$new_user_id', '$friend_id')
        ";
    
        mysql_query($sql);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Dear friends,I want to extract text 平均3.6 星 from this code segment excerpted from
I got this script off 9lessons.info and it is supposed to auto suggest friends
friends, here is my layout with image and text. i want to show text
hi my dear friends : the below code works perfect in ie9 , but
How are you all my friends, after a very hard time I got this
User Class - Name - Picture Friend Class - Profile Of Type User -
Finally, I find some article in http://code.google.com/intl/en/web/ajaxcrawling/docs/getting-started.html msnbc use this method. Thanks for all
I've gone through several similar questions, none seem to deal with this type of
I'm trying to create test users (works) and then invite them to my app
Hi, I know this should be really simple but I am just too new

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.