搜索

public function ajax_sear()
    {
         $k_word = empty($_POST['k_word']) ? '' : $data = $_POST['k_word'];//關鍵字
         $year = empty($_POST['year']) ? '' : $data = $_POST['year'];//時間
         $catid = empty($_POST['catid']) ? '' : $data = $_POST['catid'];
         //過濾
        $k_word = safe_replace(trim($k_word));
        $k_word = new_html_special_chars(strip_tags($k_word));
        $k_word = str_replace('%', '', $k_word);   
         // 處理時間
        date_default_timezone_set('Asia/Shanghai'); 
        $year = strtotime($year);
        $next_year = $year + 31536000;
        $sql_time = "a.inputtime >" .$year. " and a.inputtime <" .$next_year;
        //條件
        $from = "from v9_download as a , v9_download_data as b where a.id=b.id and a.catid='$catid'";
        $limit = 2; 
        //判斷搜索條件
        if(!empty($k_word))
        {
            $from .= "and a.title like'%$k_word%'";
        }
        if(!empty($year))
        {
            $from .= 'and '.$sql_time;
        }
        //查詢出來的個數
        // $sql_count = "select count(*) as count ". $from;
        // $data_count = $this->db->fetch_array($this->db->query($sql_count));
        // $count = $data_count[0][count];
        //執行搜索  
        $sql = "select a.title, a.url, a.inputtime,b.content,b.downfiles ".$from /*. "limit $limit"*/;
        $result = $this->db->query($sql);
        $result = $this->db->fetch_array($result);
        $str .= "<ul class='downloadList'>";
        foreach($result as $v){
             $down_url = string2array($v['downfiles']);
            $str .='<li>
                        <h3 class="clearfix">
                            <p class="tit">•'.$v[title].'</p>
                            <a href="'.$down_url[0][fileurl].'" class="btn">下載</a>
                        </h3>
                        <div class="downTxt">'.$v[content].'</div>
                    </li>';
        }
        $str .= '</ul>';
        echo $str;
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章