이 코드는 다음과 같이 실행합니다. 데이터베이스의 모든 값을 표시하며 검색 할 때 검색합니다.하지만 예상 한 결과는 실행시 데이터를 표시하지 않아야합니다. 데이터베이스 및 검색 할 때만 결과를 표시해야합니다.검색하기 전에 db에서 값 가져 오기
컨트롤러 search1_site.php
<?php
class Search1_site extends ci_controller
{
function index()
{
$data = array();
$keyword = $this->input->post('keyword');
$data['results'] = $this->search1_model->search($keyword);
$this->load->view('result_view', $data);
}
}
?>
모델 search_model.php
<?php
class Search_model extends CI_Model
{
function search($keyword)
{
$this->db->like('course_code', $keyword);
$query = $this->db->get('coursemaster');
return $query->result();
}
}
?>
보기 result_view.php 페이지가 컨트롤러에 다음 줄에 키워드를로드
<form action="<?php echo site_url('search1_site/index');?>" method = "post">
<input type="text" name = "keyword" />
<input type="submit" id="opn" value = "Search" />
</form>
<table>
<tr>
<th>course_code</th>
<th>course name</th>
</tr>
<?php
foreach ($results as $row) {
?>
<tr>
<td><?php echo $row->course_code;?></td>
<td><?php echo $row->course_name;?></td>
</tr>
<?php
}
?>
</table>
난 정말 당신의 코드를 좋은 볼 않았지만, 일반적으로, 당신이 원하는 검색을 수행 할 데이터베이스, 데이터베이스는 PHP 및 배열보다 훨씬 빠릅니다. – Martijn