【发布时间】:2013-12-14 18:15:58
【问题描述】:
到目前为止,我的应用程序将输入的单词输入到文本框中,然后检查数据库列是否存在完全相同的匹配字符串,然后在视图中显示结果。
我的控制器:
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 = "' . $question_category . '"');
return $resultsset;
}
我的看法:
<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;
}
}
?>
如果我搜索“red”并且在 db 表列中有一个名为“red”的标题,它将显示在结果中。
但是,如果我搜索“红色”并且在 db 表列中有一个名为“大红色汽车”的标题,我也希望在结果中返回它,因为目前它没有。
也许可以使用“stristr”类型的函数?如果有怎么办?
【问题讨论】:
标签: php mysql codeigniter