繁体   English   中英

从数据库获取匹配短语

[英]Get matching phrase from database

到目前为止,我的应用程序将单词输入到文本框中,然后检查数据库列是否存在完全相同的匹配字符串,然后在视图中显示结果。

我的控制器:

 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;
    } 
  }
?>

如果我搜索“红色”,并且在数据库表列中有一个名为“红色”的标题,它将显示在结果中。

但是,如果我搜索“红色”并且在数据库表列中有一个名为“大红色汽车”的标题,我也希望在结果中返回该名称,因为目前它还没有。

也许可以使用“ stristr”类型的功能? 如果是这样怎么办?

使用喜欢查询

public function lookup($question_category)
{
$resultsset = $this->db->get_where('question', 
  'question_title like "%' .  $question_category . '%"');
return $resultsset;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM