display data using search via ajax
<p>I am using search functionality via ajax in codeigniter... The code is working fine... it properly search the required match but the problem with my code is that it is displaying 2 things in view 1. by default values 2.searched values
But i want is it display default values once when i search then only searched values not default values.
My controller is: </p>

<pre><code>public function seller()
{
    $this-&gt;load-&gt;model('home/Home_model');
    $ser = $this-&gt;input-&gt;post('search_data');
   if(isset($search))
   {
    $data['h'] = $this-&gt;Home_model-&gt;search_seller($search);     
    }
    else
    {
    $data['h'] = $this-&gt;Home_model-&gt;seller();       
    }
    $this-&gt;load-&gt;view('admin/pages/sellers', $data);    
}
</code></pre>

<p>My model is </p>

<pre><code>      public function seller()  
  {  
     $query = $this-&gt;db-&gt;get('wc_seller');  
     return $query;  
  } 
    public function search_seller($search)
    {
    $this-&gt;db-&gt;select('*');
    $this-&gt;db-&gt;like('seller_name', $search);
    $this-&gt;db-&gt;like('email', $search);
    $query = $this-&gt;db-&gt;get('wc_seller');
     return $query;
</code></pre>

<p>}
view is</p>

<pre><code>foreach ($h-&gt;result() as $row)  
     {  
        ?&gt;
        &lt;form action="&lt;?php echo base_url() . "Home/edit_sellers/" . $row-&gt;id; ?&gt;" method="POST"&gt;
                &lt;tr&gt;
                    &lt;th scope="row"&gt;&lt;?php echo $i; ?&gt;&lt;/th&gt;
                    &lt;td&gt;&lt;?php echo $row-&gt;last_modified;?&gt; &lt;/td&gt;
                    &lt;td&gt;&lt;?php echo $row-&gt;email; ?&gt;&lt;/td&gt;
                    &lt;input type="hidden" name="id" value="&lt;?php echo $row-&gt; id; ?&gt;"&gt;
                    &lt;td&gt;&lt;input type="text" name="seller_name" value="&lt;?php echo $row-&gt;seller_name;?&gt;" placeholder="&lt;?php echo $row-&gt;seller_name;?&gt;" class="form-control"&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;input type="text" name="mobile_no" value="&lt;?php echo $row-&gt;mobile_no;?&gt;" placeholder="&lt;?php echo $row-&gt;mobile_no;?&gt;" class="form-control"&gt;&lt;/td&gt;
                    &lt;td&gt;
  &lt;/form&gt;
    &lt;?php } ?&gt;
</code></pre>

<p>my ajax script is</p>

<pre><code>       &lt;?php $this-&gt;load-&gt;view('admin/templates/header'); ?&gt;       

 &lt;div id="page-wrapper"&gt;
&lt;div class="graphs"&gt;
&lt;h3 class="blank1"&gt;All Sellers&lt;/h3&gt;
&lt;div class="something"&gt;
 &lt;input name="search_data" id="search_data" type="text" onkeyup="ajaxSearch();"&gt;
    &lt;div id="suggestions"&gt;
        &lt;div id="autoSuggestionsList"&gt;  
        &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="xs tabls tabls1"&gt;
     &lt;div class="panel-body1"&gt;
         &lt;table class="table table-hover table-responsive"&gt;
             &lt;thead&gt;

                    &lt;tr&gt;
                    &lt;th&gt;Id&lt;/th&gt;
                    &lt;th&gt;Registered On&lt;/th&gt;
                    &lt;th&gt;Email&lt;/th&gt;
                    &lt;th&gt;Full Name&lt;/th&gt;
                    &lt;th&gt;Mobile No&lt;/th&gt;
                    &lt;th&gt;Actions&lt;/th&gt;
                &lt;/tr&gt;
            &lt;/thead&gt;
            &lt;tbody&gt;
    &lt;?php  
    $i = 1; 
     foreach ($h-&gt;result() as $row)  
     {  
        ?&gt;
        &lt;form action="&lt;?php echo base_url() . "Home/edit_sellers/" . $row-&gt;id; ?&gt;" method="POST"&gt;
                &lt;tr&gt;
                    &lt;th scope="row"&gt;&lt;?php echo $i; ?&gt;&lt;/th&gt;
                    &lt;td&gt;&lt;?php echo $row-&gt;last_modified;?&gt; &lt;/td&gt;
                    &lt;td&gt;&lt;?php echo $row-&gt;email; ?&gt;&lt;/td&gt;
                    &lt;input type="hidden" name="id" value="&lt;?php echo $row-&gt; id; ?&gt;"&gt;
                    &lt;td&gt;&lt;input type="text" name="seller_name" value="&lt;?php echo $row-&gt;seller_name;?&gt;" placeholder="&lt;?php echo $row-&gt;seller_name;?&gt;" class="form-control"&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;input type="text" name="mobile_no" value="&lt;?php echo $row-&gt;mobile_no;?&gt;" placeholder="&lt;?php echo $row-&gt;mobile_no;?&gt;" class="form-control"&gt;&lt;/td&gt;
                    &lt;td&gt;

                    &lt;button type="submit" value="Update" class="btn btn-primary btn-sm"&gt;Update&lt;/button&gt;
                    &lt;a type="button" class="btn btn-danger btn-sm" href="&lt;?php echo base_url() . "Home/delete_seller/" . $row-&gt;id; ?&gt;" onclick="return confirm('Are you sure you want to delete it?')"&gt;&lt;i class="fa fa-trash-o" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;

                    &lt;?php if($row-&gt;status == '1' ){
                    $status = 'Deactivate';
                    }
                    else{
                        $status = 'Activate';

                    }
                    ?&gt;
                    &lt;button type="button" class="btn btn-success btn-sm" id="&lt;?php echo $row-&gt;id; ?&gt;"  onclick="savestatus&lt;?php echo $row-&gt;id; ?&gt;(&lt;?php echo $row-&gt;id; ?&gt;)"&gt;&lt;?php echo $status; ?&gt;&lt;/button&gt;



                    &lt;/td&gt;
                &lt;/tr&gt;
    &lt;/form&gt;
    &lt;script&gt;
 function savestatus&lt;?php echo $row-&gt;id; ?&gt;(row_id){

  $.ajax({
    type: "POST",
    url: "&lt;?php echo base_url().'home/activate_seller/'. $row-&gt;id; ?&gt;",
    data:{},       
    success:function( data )
    {
       //$("#"+row_id).html("Deactivate");
       $("#"+row_id).text().trim()==="Activate"?         $("#"+row_id).text("Deactivate"):$("#"+row_id).text("Activate")
    }
   });
    }

    &lt;/script&gt;

        &lt;?php 
         $i++;

        }  

          ?&gt; 
            &lt;/tbody&gt;
        &lt;/table&gt;
    &lt;/div&gt;
     &lt;/div&gt;
    &lt;/div&gt;

        &lt;script type="text/javascript"&gt;
          function ajaxSearch() {
        var input_data = $('#search_data').val();
        if (input_data.length === 0) {
            $('#suggestions').hide();
            //$('.tabls1').show();
        } else {

            var post_data = {
                'search_data': input_data,
                '&lt;?php echo $this-&gt;security-&gt;get_csrf_token_name(); ?&gt;': '&lt;?php echo $this-&gt;security-&gt;get_csrf_hash(); ?&gt;'
            };

            $.ajax({
                type: "POST",
                url: "&lt;?php echo base_url().'home/seller/' ?&gt;",
                data: post_data,
                success: function(data) {
                    // return success
                    if (data.length &gt; 0) {
                        $('#suggestions').show();
                        //$('.tabls1').hide();
                        $('#autoSuggestionsList').addClass('auto_list');
                        $('#autoSuggestionsList').html(data);
                    }
                }
            });

        }
       }
   &lt;/script&gt;

  &lt;?php $this-&gt;load-&gt;view('admin/templates/footer'); ?&gt;
</code></pre>