:::

9-1 search.php

<?php
require_once 'header.php';
$page_title = '搜尋';

// die(var_dump($_SESSION));

$op      = isset($_REQUEST['op']) ? filter_var($_REQUEST['op']) : '';
$keyword = isset($_REQUEST['keyword']) ? filter_var($_REQUEST['keyword']) : '';

/*************控制器**************/

switch ($op) {

    default:
        search_article($keyword);
        $op = 'search_article';
        break;
}

require_once 'footer.php';

/*************函數區**************/

//搜尋所有文章
function search_article($keyword = '')
{
    global $db, $smarty;

    if ($keyword) {
        $keys = explode(' ', $keyword);
    } else {
        header('location:index.php');
        exit;
    }

    $key_array = array();
    foreach ($keys as $value) {
        if ($value != '') {
            $key_array[] = "(a.`title` LIKE '%{$value}%' OR a.`content` LIKE '%{$value}%')";
        }
    }

    if (empty($key_array)) {
        header('location:index.php');
        exit;
    }

    $search_str = implode(' or ', $key_array);

    $sql = "SELECT a.*, b.* FROM `article` AS a
    LEFT JOIN `topic` AS b ON a.`topic_sn` = b.`topic_sn`
    WHERE $search_str ORDER BY a.`update_time` DESC ";

    include_once "PageBar.php";
    $PageBar = getPageBar($db, $sql, 3, 10);
    $bar     = $PageBar['bar'];
    $sql     = $PageBar['sql'];
    $total   = $PageBar['total'];

    $result = $db->query($sql) or die($db->error);
    $all    = array();
    $i      = 0;
    while ($data = $result->fetch_assoc()) {
        $all[$i]            = $data;
        $all[$i]['summary'] = mb_substr(strip_tags($data['content']), 0, 90);
        $i++;
    }
    // die(var_export($all));
    $smarty->assign('all', $all);
    $smarty->assign('bar', $bar);
    $smarty->assign('total', $total);

}

 


:::

搜尋

QR Code 區塊

https%3A%2F%2Ftad0616.cp27.secserverpros.com%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D1417%26tbsn%3D43

書籍目錄

展開 | 闔起

線上使用者

358人線上 (141人在瀏覽線上書籍)

會員: 0

訪客: 358

更多…