2013-12-14 12 views
0

내 응용 프로그램은 지금까지 텍스트 상자에 입력 된 단어를 가져온 다음 정확히 일치하는 문자열이 있는지 데이터베이스 열을 검사 한 다음 결과를보기에 표시합니다.데이터베이스에서 일치하는 구문 가져 오기

내 컨트롤러 :

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

내가 '빨간색'검색에서 '빨간색'라는 제목이있는 경우 결과에 db 테이블 열이 표시됩니다.

그러나 'red'를 검색하고 'big red car'라는 제목이 db 테이블 coloumn에 있으면 나는 그 결과로 반환되기를 원합니다. 지금은 그렇지 않습니다.

아마도 'stristr'유형의 기능을 사용할 수 있습니까? 그렇다면 어떻게?

답변

1

사용처럼 쿼리

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

큰 배열 사용 json_decode ($ 배열)에 결과를 가져 오는 한 후 JSON – sunrise3333

+0

에 결과를 표시하는 방법이 –

관련 문제