首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >CodeIgniter Sql语法不起作用

CodeIgniter Sql语法不起作用
EN

Stack Overflow用户
提问于 2012-10-15 10:02:25
回答 1查看 233关注 0票数 2

好的,我来了,直截了当的说我需要一些建议

所以在这里我遇到了一些关于“数据库”的问题,这是代码

代码语言:javascript
运行
复制
    $as="&";
    $string1="title=";
    $a= $this->input->post('title');
    $string2="category=";
    $b= $this->input->post('category');
    $string3="length_comparison=";
    $c= $this->input->post('length_comparison');
    $string4="length=";
    $d= $this->input->post('length');


    $combine=$string1.$a.$as.$string2.$b.$as.$string3.$c.$as.$string4.$d;


    $this->db->select('*');
    $this->db->from('ci_query');
    $this->db->where('ci_query.query_string',$combine);             
    $query = $this->db->get();
    $rows=$query->result();
    $count=0;

    foreach($rows as $row)
    {
        $count=$count+1;
        $query_id = $row->id;
    }

    if($count==0)
    {
        $query_id = $this->input->save_query($query_array);
    }


    redirect("films/display/$query_id");

逻辑是这样的

代码语言:javascript
运行
复制
 1. i got an input from a search form  tittle,category,length_comparison,and length.
 2. first case these logic will save all those input into a column in a table, all in 1 column, if there is no same parameter
"tittle,category,length_comparison,and length" in the table.
 3. but if there is any same parameter it will not insert to the table, and just redirect to the page i choose
 4. from the table we got the id and display instead of using long query string. display the search result.

我的问题:我已经完成了编码,它在我的计算机/pc上工作得很好。但是当我使用我的笔记本电脑时,它就是不能工作,有人能给我一些建议吗?还是我的编码?还是词的版本?不然呢?

更新:

我认为这不是问题所在,因为我覆盖了lib,所以我有这个来使用那个函数

代码语言:javascript
运行
复制
function save_query($query_array) {

    $CI =& get_instance();

    $CI->db->insert('search', array('query_string' => http_build_query($query_array)));

    return $CI->db->insert_id();
}

function load_query($query_id) {

    $CI =& get_instance();

    $rows = $CI->db->get_where('search', array('id' => $query_id))->result();
    if (isset($rows[0])) {
        parse_str($rows[0]->query_string, $_GET);       
    }

}

}

EN

回答 1

Stack Overflow用户

发布于 2012-10-16 07:51:46

您需要使用:

代码语言:javascript
运行
复制
if($count==0)
{
    $this->db->insert('ci_query', array('query_string' => $combine));
    $query_id = $this->db->insert_id();
}

这样,您就插入了正确的数据,并且从数据库中读取了正确的ID。

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

https://stackoverflow.com/questions/12888385

复制
相关文章

相似问题

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