<?php
define('CURSCRIPT', 'search');
require_once './engine/common.inc.php';
$type_allowed=array(1,2,3);
if(!in_array($type,$type_allowed)){
	showmsg("对不起，传入参数有误");
}
$pagerecords=15;
$siteheadtitle=implode(' ',array('网站搜索',$sitename,$sitekeywords));
$toparticles=array();
$searchword = str_replace(array('&', '"', '<', '>' , '\''), array('&amp;', '&quot;', '&lt;', '&gt;' , '&quot;'), $searchword);
$db_table=array(1=>'g_articles',2=>'g_products',3=>'g_threads');
$db_searchword=array(1=>'articletitle',2=>'producttitle',3=>'title');
$db_searchid=array(1=>'aid',2=>'productid',3=>'tid');
$show_page=array(1=>'viewarticle.php?aid=',2=>'viewproduct.php?productid=',3=>'viewthread.php?tid=');
$curpage=isset($page)?$page:1;
$startrecord=($curpage-1)*$pagerecords;
$totalrecord=$db->result($db->query("SELECT count(*) FROM {$db_table[$type]} WHERE {$db_searchword[$type]} like '%$searchword%'"),0);
if(!$totalrecord){
	showmsg("没有查询到相关内容");
}
$q = $db->query("SELECT * FROM {$db_table[$type]} WHERE {$db_searchword[$type]} like '%$searchword%' ORDER BY ord DESC LIMIT $startrecord , $pagerecords");
$key=0;
while($s_result=$db->fetch_array($q)){
		$s_result['searchtitle']=$s_result[$db_searchword[$type]];
		$s_result['url']=$show_page[$type].$s_result[$db_searchid[$type]];
		$search_result[$key]=$s_result;
		$key++;
	}
$multipage=multi($totalrecord , $pagerecords , $curpage , "search.php?searchword=".$searchword."&type=".$type);
include($templatedir."search.tpl.php");

?>