:::

10. 加入搜尋

  1. 先至後台區塊管理,啟用XOOPS的搜尋區塊。
  2. 在xoops_version.php中加入搜尋設定(記得更新模組):
    //---搜尋---//
    $modversion['hasSearch']      = 1;
    $modversion['search']['file'] = "include/search.php";
    $modversion['search']['func'] = "tad_signup_search";
  3. 編輯 include/search.php,並根據提示修改之。
    <?php
    function tad_signup_search($queryarray, $andor, $limit, $offset, $userid)
    {
        global $xoopsDB;
        if (get_magic_quotes_gpc()) {
            foreach ($queryarray as $k => $v) {
                $arr[$k] = addslashes($v);
            }
            $queryarray = $arr;
        }
        $sql = "SELECT `action_id`,`title`,`action_date`, `uid` FROM " . $xoopsDB->prefix("actions") . " WHERE `enable`=1";
        if ($userid != 0) {
            $sql .= " AND uid=" . $userid . " ";
        }
        if (is_array($queryarray) && $count = count($queryarray)) {
            $sql .= " AND ((`title` LIKE '%{$queryarray[0]}%'  OR `content` LIKE '%{$queryarray[0]}%' )";
            for ($i = 1; $i < $count; $i++) {
                $sql .= " $andor ";
                $sql .= "(`title` LIKE '%{$queryarray[$i]}%' OR  `content` LIKE '%{$queryarray[$i]}%' )";
            }
            $sql .= ") ";
        }
        $sql .= "ORDER BY  `action_date` DESC";
        $result = $xoopsDB->query($sql, $limit, $offset);
        $ret    = array();
        $i      = 0;
        while ($myrow = $xoopsDB->fetchArray($result)) {
            $ret[$i]['image'] = "images/search.png";
            $ret[$i]['link']  = "index.php?action_id=" . $myrow['action_id'];
            $ret[$i]['title'] = $myrow['title'];
            $ret[$i]['time']  = strtotime($myrow['action_date']);
            $ret[$i]['uid']   = $myrow['uid'];
            $i++;
        }
        return $ret;
    }
    
  4. 圖示請準備16x16的圖示,並存為 images/search.png。(可至 https://www.flaticon.com 下載)

:::

書籍目錄

展開 | 闔起

快速登入


http%3A%2F%2Fcampus-xoops.tn.edu.tw%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D920%26tbsn%3D29

計數器

今天: 772772772
昨天: 3068306830683068
總計: 8077277807727780772778077277807727780772778077277