Jatinder_1 0 Newbie Poster

problem in getting live data in my web page

search_ajax.js

$(document).ready(function() {  

    // Icon Click Focus
    /*$('div.icon').click(function(){
        $('input#search').focus();
    });*/

    // Live Search
    // On Search Submit and Get Results
    function search() {
        var query_value = $('input#search').val();  
        $('b#search-string').html(query_value); 
        if(query_value !== ''){
            $.ajax({
                type: "POST",
                url: "search_ajax.php",
                data: { query: query_value },
                cache: false,
                success: function(html){
                    $("#results").val(html);
                }
            });
        }return false;    
    }

    $("input#search").on("keyup", function(e) {
        // Set Timeout
        clearTimeout($.data(this, 'timer'));
        // Set Search String
        var search_string = $(this).val();
        // Do Search
        if (search_string == '') {
            $("#results").fadeOut();
            $('#results-text').fadeOut();
        }else{
            $("#results").fadeIn();
            $('#results-text').fadeIn();
            $(this).data('timer', setTimeout(search(), 100));
        };
    });

});

search_ajax.php

<?php

$connection = mysql_connect("localhost","root","");
$connection = mysql_select_db("database", $connection);
$msg='';

$search_string = "";

$search_string = $_POST['query'];

if (strlen($search_string) >= 1 && $search_string !== ' ') {

$query = mysql_query("SELECT fname FROM user WHERE id LIKE '%$search_string%'",$connection)
  or die ('Error: '.mysql_error());

  $result = $connection->query($query);
  while($results = $result->fetch_array()) {
    $result_array[] = $results;
  }

  if (isset($result_array)) {
    foreach ($result_array as $result) {

    $display_fname = preg_replace("/".$search_string."/i", "<b class='highlight'>".$search_string."</b>", $result['fname']);
    $output =( $display_fname, $output);

    echo($output);
    }
  }else{
    // Format No Results Output
    $output = ( '<b>No Results Found.</b>', $output);

    echo($output);
  }
}

?>

HTML Part is

<tr>
              <td style="border-bottom:#DFDFDF 1px solid">Sponsor ID <span style="color: #F00">*</span></td>
              <td style="border-bottom:#DFDFDF 1px solid"><span id="sprytextfield4">
                <input type="text" name="sponsor" id="search" value="" autocomplete="off" />
                <br />
                <span class="textfieldRequiredMsg">Sponsor ID is required.</span></span></td>
            </tr>
                                        <tr>
                          <td style="border-bottom:#DFDFDF 1px solid">Sponsor Name</td>
                          <td style="border-bottom:#DFDFDF 1px solid">
                            <input type="text" name="sponsor2" id="results" value="" readonly />

                            </td>
                </tr>
                <tr>

Sposor ID query goes to check ID or user (same data in ID and user row) and display fname

Please solve this problem, thanks in advance