0

OK i am having trouble with JQuery autocomplete.

In search bar when i start typing it just shows firstname from searchfrnds.php. What i want is that it should somehow concatenate the result from searchfrnds.php in such a way that it shows firstname as well as lastname in the search result drop down that displays.

Code for searchfrnds.php:

  <?php 
   $term = trim(strip_tags($_GET['term']));

   $query = "SELECT aid,firstname, lastname, profpic,email,abtyou
    FROM artist92 WHERE firstname LIKE '%".$term."%' OR lastname LIKE '%".$term."%'";


    $result = mysqli_query ($link, $query);


    $array = array();

    while($obj = mysqli_fetch_array($result, MYSQLI_ASSOC)){
    $array['value'] = $obj['firstname'];
$array['lvalue'] = $obj['lastname'];
$array['icon'] = $obj['profpic'];
$array['aid']=$obj['aid'];
$array['abt']=$obj['abtyou'];
$array['email']=$obj['email'];

$row_set[]=$array;


       }

        echo json_encode($row_set);

      ?>

JQuery code :

  <script>

$(function() {
    function log( message ) {
        $( "<div>" ).text( message ).prependTo( "#log" );
        $( "#log" ).scrollTop( 0 );
    }

    $( "#frndsrch" ).autocomplete({
        source: "searchfrnds.php",
        minLength: 2,
        select: function( event, ui ) {
             $( "#project-icon" ).attr( "src", "" + ui.item.icon );
            $('a').attr('href',"viewartprofile.php?aid=" + ui.item.aid ); 

                 }
    });


});
</script>
1
  • write you jquery code not only PHP.. Commented Oct 23, 2012 at 13:24

2 Answers 2

2

Assuming jQueryUI autocomplete is displaying the value part of the array, just do:

$array['value'] = $obj['firstname'].' '.$obj['lastname'];

And then that should display both as required.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh god! why didn't i think of it? Thanks for the help.
0

jquery ui autocomplete's item's label is showed (& searched by default) and value is inserted if the option is selected - if one is ommitted, other's value is copied & used.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.