Php 从数据库中获取匹配短语
到目前为止,我的应用程序将单词输入到文本框中,然后检查数据库列是否存在完全相同的匹配字符串,然后在视图中显示结果 我的控制器:Php 从数据库中获取匹配短语,php,mysql,codeigniter,Php,Mysql,Codeigniter,到目前为止,我的应用程序将单词输入到文本框中,然后检查数据库列是否存在完全相同的匹配字符串,然后在视图中显示结果 我的控制器: public function questions() { //Pick up what was typed in the text box named "query" $question = $this->input->get("query"); //Extract the correct data from the model
public function questions()
{
//Pick up what was typed in the text box named "query"
$question = $this->input->get("query");
//Extract the correct data from the model.
$details = $this->questions_model->lookup($question);
$x = $details->result();
print"<pre>";print_r($x);print"</pre>";
print gettype($x);
//Display data on the web page.
$this->load->view('findquestions', array('items' => $x));
}
我的看法是:
public function lookup($question_category)
{
$resultsset = $this->db->get_where('question',
'question_title like "%' . $question_category . '%"');
return $resultsset;
}
查找问题:
如果我搜索“red”,并且db表格列中有一个名为“red”的标题,它将显示在结果中
然而,如果我搜索“red”,在db表column中有一个名为“big red car”的标题,我也希望在结果中返回它,因为目前它没有返回
也许可以使用“stristr”类型的函数?如果是,如何使用?使用Like查询
很好,有没有办法用json显示结果
<form action='/cw2/index.php/search/questions' method="GET">
Find Question: <input type="text" name="query">
</form>
<?php
if (isset($items)) {
foreach($items as $i){
print $i->question_title . " " . $i->question_category;
}
}
?>
public function lookup($question_category)
{
$resultsset = $this->db->get_where('question',
'question_title like "%' . $question_category . '%"');
return $resultsset;
}