数据未在Ajax Codeigniter中过滤 [英] data not filtering in ajax codeigniter

查看:218
本文介绍了数据未在Ajax Codeigniter中过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过下拉列表过滤数据,但是它给了我所有数据...。

I want to filter data by dropdown but it giving me all data....

这是我的带有ajax函数的模型

this is my model with ajax function

public function ajax()
{
     $query = "SELECT * from info_user Where user_status ='1'"; 
    if(!empty($size)){
        $query  .= " and city in('".$size."')"; 
    }
    if(!empty($sprice) && !empty($eprice)){
        $query  .=  " and charge_per_hour >='".$sprice."' and 
        charge_per_hour <='".$eprice."'"; 
    }

    $result = $this->db->query($query);
    return $result->result();   
}

这是我的控制人

public function ajax()
{

    $size = $this->input->post('size');
    $sprice = $this->input->post('sprice');
    $eprice = $this->input->post('eprice');

    $this->load->model('ajax_model');
    $result = $this->ajax_model->ajax();


    foreach( $result as $row )
    {   
        echo $row->name.'<br>'; 
        echo $row->charge_per_hour.'<br>'; 
        echo $row->city.'<br>'; 
    }
}

这是运行代码后的结果...

This is it looks after running code...

它给了我所有数据,而不是所选数据

it giving me all data instead of selected data

https://i.imgur.com/SdwzKJ9.png

推荐答案

在这里,您必须将要发送的变量传递给模型
您没有将变量传递给模型中未包含在模型函数中的变量。

Here you have to pass the variable that you are sending to the Model. You are not passing the variable to model that was not getting in your model's function.

在下面选中此项可能会有所帮助。

Check this below that may help.

控制器

public function ajax()
{

    $size = $this->input->post('size');
    $sprice = $this->input->post('sprice');
    $eprice = $this->input->post('eprice');

    $this->load->model('ajax_model');
    $result = $this->ajax_model->ajax($size,$sprice,$eprice);


    foreach( $result as $row )
    {   
        echo $row->name.'<br>'; 
        echo $row->charge_per_hour.'<br>'; 
        echo $row->city.'<br>'; 
    }
}

模型

public function ajax($size = '',$sprice = '',$eprice = '')
{
     $query = "SELECT * from info_user Where user_status ='1'"; 
    if($size != '')){
        $query  .= " and city in('".$size."')"; 
    }
    if(($sprice != '') && ($eprice != '')){
        $query  .=  " and charge_per_hour >='".$sprice."' and 
        charge_per_hour <='".$eprice."'"; 
    }

    $result = $this->db->query($query);
    return $result->result();   
}

这篇关于数据未在Ajax Codeigniter中过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆