首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Codeigniter数据库问题

Codeigniter数据库问题
EN

Stack Overflow用户
提问于 2010-10-15 08:30:59
回答 1查看 260关注 0票数 1

有一点麻烦试图从我的数据库中抓取一些数据。

我有以下模型:

代码语言:javascript
运行
复制
function GetRestaurants($options = array())
    {
        // Qualification
        if(isset($options['restaurantID']))
            $this->db->where('restaurantID', $options['restaurantID']);
        if(isset($options['restaurantRegionID']))
            $this->db->where('restaurantRegionID', $options['restaurantRegionID']);
        if(isset($options['restaurantName']))
            $this->db->where('restaurantName', $options['restaurantName']);
        if(isset($options['restaurantAddress1']))
            $this->db->where('restaurantAddress1', $options['restaurantAddress1']);
        if(isset($options['restaurantAddress2']))
            $this->db->where('restaurantAddress2', $options['restaurantAddress2']);
        if(isset($options['restaurantSuburb']))
            $this->db->where('restaurantSuburb', $options['restaurantSuburb']);
        if(isset($options['restaurantCity']))
            $this->db->where('restaurantCity', $options['restaurantCity']);
        if(isset($options['restaurantInformation']))
            $this->db->where('restaurantInformation', $options['restaurantInformation']);

        // limit / offset
        if(isset($options['limit']) && isset($options['offset']))
            $this->db->limit($options['limit'], $options['offset']);
        else if(isset($options['limit']))
            $this->db->limit($options['limit']);

        // sort
        if(isset($options['sortBy']) && isset($options['sortDirection']))
            $this->db->order_by($options['sortBy'], $options['sortDirection']);

        $query = $this->db->get("tblRestaurants");

        if(isset($options['count'])) return $query->num_rows();

        if(isset($options['restaurantID']))
            return $query->row(0);

        if(isset($options['limit']) && $options['limit'] == '1')
            return $query->row(0);

        return $query->result();
    } 

现在,以下代码可以正常工作:

代码语言:javascript
运行
复制
$this->load->model('Restaurants_model');
        $data['restaurant'] =  $this->Restaurants_model->GetRestaurants(array(
            'restaurantName' => 'shed 5', 
            'limit' => '1'
            )); 

但是,以下操作不起作用:

代码语言:javascript
运行
复制
$this->load->model('Restaurants_model');
        $data['restaurant'] =  $this->Restaurants_model->GetRestaurants(array(
            'restaurantName' => str_replace('-', ' ', $this->uri->segment(2)), 
            'limit' => '1'
            )); 

即使结果是

代码语言:javascript
运行
复制
str_replace('-', ' ', $this->uri->segment(2)) 

在这个例子中是:‘shed 5’。

我比较了str_replace的输出和字符串本身的var_dumps,并确定它们是相同的。那么,为什么直接字符串会返回结果,而从uri段生成的字符串却不会呢?某种编码问题?我的数据库将数据保存在‘utf8_general_ci’中。

谢谢你的建议!

EN

回答 1

Stack Overflow用户

发布于 2010-10-16 00:10:38

$restaurant=str_replace('-',‘',$this->uri->段(2));

从数组外部获取值并尝试array_push

$data‘$restaurant’= $this->Restaurants_model->GetRestaurants(array( 'restaurantName‘=> $restaurant,'limit’=> '1‘);

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3938607

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档