Skip to content

Commit f671799

Browse files
committed
CodeIgniter-Blog v2.4.5 Optimize search page code.
1 parent 6a80918 commit f671799

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

application/controllers/Home.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public function message()//留言功能
123123
function search()//搜索功能
124124
{
125125
$keyword = $this->input->post('keyword');
126+
126127
$data['rows'] = $this->home_model->search($keyword);
127128
$this->load->view('search', $data);
128129
}

application/models/Home_model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function message($name, $content, $date)
8080

8181
function search($keyword)
8282
{
83-
$data = $this->db->from('article')->like('title', $keyword)->or_like('content', $keyword)->get();
83+
$data = $this->db->like('title', $keyword)->or_like('content', $keyword)->get('article');
8484
return $data->result();
8585
}
8686
}

application/views/search.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
<!--left-->
2626
<div class="left" id="learn">
2727
<div class="content_text">
28-
<?php if ($rows) {?>
29-
<?php foreach($rows as $row){ ?>
28+
<?php if (($rows)) { foreach ($rows as $row):?>
3029
<div class="article-title">
3130
<h1><?php echo $row->title;?></h1>
3231
</div>
@@ -36,7 +35,7 @@
3635
<div class="article-content">
3736
<p><?php echo $row->content;?></p>
3837
</div>
39-
<?php } }else{?>
38+
<?php endforeach; } else {?>
4039
<?php echo '<div class="article-title">' . '<h1>' . '服务器君暂时没有找到结果,请稍后再来。' . '</h1>' . '</div>';} ?>
4140
</div>
4241
</div>

0 commit comments

Comments
 (0)