Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Retrieved data from codeigniter not displaying on page

I have this code that's giving me issues. What I did was to extract data from database into tables and with a search text that can be used to search data from the table data without having to refresh the page. At first when, everything worked fine; but all of a sudden, it stopped displaying the table.

Here's is the controller:

function fetch(){
     $output='';
     $query='';
     if($this->input->post('query')){
        $query = $this->input->post('query');
     }
    $data_fetch = $this->ManagerModel->get_attend($query);

    $output .='
    <table class="table table-hover table-bordered">
        <tr style="font-weight:bold; background-color:#f5f5f5; text-transform:uppercase; color:#006;">
            <td>Fullname</td> 
            <td>Email</td>
            <td>title</td>
            <td>category</td>
            <td>zone</td>
            <td>chapter</td>
            <td>country</td>
            <td>KCN</td>
            <td>date</td>
        </tr>';
        if($data_fetch->num_rows()>0){
            foreach($data_fetch->result() as $row)
                $output .='
                    <tr>                
                        <td>'.$row->fname.'</td>
                        <td>'.$row->email.'</td>
                        <td>'.$row->title.'</td>
                        <td>'.$row->category.'</td>
                        <td>'.$row->zone.'</td>
                        <td>'.$row->chapter.'</td>
                        <td>'.$row->country.'</td>
                        <td>'.$row->kcn.'</td>
                        <td>'.$row->date_added.'</td>
                    </tr>
                ';
        }
        else
        {
            $output.='<tr> <td>No data Found</td></tr>';
        }
        $output .='</table>';
        echo $output;

 }

Here's my model:

public function get_attend($query){

$this->db->select("*");
$this->db->from("attendance");
if($query !='')
{
    $this->db->like('zone', $query);
    $this->db->or_like('title', $query);
    $this->db->or_like('country', $query);
    $this->db->or_like('date_added', $query);
    $this->db->or_like('chapter', $query);
    $this->db->or_like('category',$query);
    $this->db->or_like('email', $query);
    $this->db->or_like('kcn', $query);
}
$this->db->order_by('id', 'DESC');
return $this->db->get();

}

Here's my ajax code:

 $(document).ready(function(){

    load_data();

    function load_data(query){
        $.ajax({
            url:"<?php echo base_url(); ?>manager/fetch",
            method:"POST",
            data:{query:query},
            success:function(data){
                $('#result').html(data);
            }
        })
    }
    $('#search_text').keyup(function(){
        var search = $(this).val();
        if(search !=''){
            load_data(search);
        }
        else{
            load_data();
        }
    });
 });

And here's my view:

<div id="result"></div>

What can I do to resolve this problem?

Comments