好的,我来了,直截了当的说我需要一些建议
所以在这里我遇到了一些关于“数据库”的问题,这是代码
$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");逻辑是这样的
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,所以我有这个来使用那个函数
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);
}
}}
发布于 2012-10-16 07:51:46
您需要使用:
if($count==0)
{
$this->db->insert('ci_query', array('query_string' => $combine));
$query_id = $this->db->insert_id();
}这样,您就插入了正确的数据,并且从数据库中读取了正确的ID。
https://stackoverflow.com/questions/12888385
复制相似问题