在->or_where('text like',"%dog%")
不工作。我用它来做一个json格式在数据表中查看请帮帮我!
$this->datatables->select('id,name,text,profile_image_url') //Ignited datatables
->unset_column('id')
->unset_column('profile_image_url')
->unset_column('name')
->unset_column('text')
->add_column('profile_image_url', '<img src="$1"/>', 'profile_image_url')
->add_column('name','$1','name')
->add_column('text','$1','text')
->where('text like',"%cat%")
->or_where('text like',"%dog%")
->from('posts');
echo $this->datatables->generate();
不起作用因为你有无效的语法,使用->表示你在比较如果列等于你的第二个参数,使用类似函数的语法应该是
$this->db->like('text', 'cat');
$this->db->like('text2', 'dog');
但是如果你想控制通配符(%)的位置,你可以使用可选的第三个参数。你的选项是'before', 'after'和'both'(这是默认的)。
$this->db->like('title', 'match', 'before');
// Produces: WHERE title LIKE '%match'
$this->db->like('title', 'match', 'after');
// Produces: WHERE title LIKE 'match%'
$this->db->like('title', 'match', 'both');
// Produces: WHERE title LIKE '%match%' which is default
希望这对你有帮助
我明白你的意思。但我只是使用了引燃数据表的代码来创建一个json数组来支持数据表上的视图。它不会在codeigniter的数据库代码中使用像"$this->db->like('text', 'cat');"这样的正常代码。
我已经试过了,它返回了一个空数组。
$this->datatables->select('id,name,text,profile_image_url')
->unset_column('id')
->unset_column('profile_image_url')
->unset_column('name')
->unset_column('text')
->add_column('profile_image_url', '<img src="$1"/>', 'profile_image_url')
->add_column('name','$1','name')
->add_column('text','$1','text')
// ->like("text","%dog%");
// ->like("text","cat");
->from('posts');
$this->db->like("text","dog");
$this->db->like("text","cat");
echo $this->datatables->generate();