首先,我们要在手机版模板的m文件夹的index.php中找到代码
原代码:
$action = isset($_GET['action']) ? addslashes($_GET['action']) : '';
在其下方加入代码:
$slkey = isset($_GET['keyword']) ? addslashes($_GET['keyword']) : '';
原代码:
$page_url = pagination($lognum, $index_lognum, $page, $pageurl);
在其下方加入代码:
if(!empty($slkey)){//搜索
$Log_Model = new Log_Model();
$page = isset($_GET['page']) ? abs(intval ($_GET['page'])) : 1;
$site_title = '搜索关键词:'.$slkey.'价格表';
$pageurl = '';
if(is_numeric($slkey)){
$sqlSegment = "and (huohao ='{$slkey}') order by date desc";}else{
$sqlSegment = "and title like '%{$slkey}%' order by date desc";}
$lognum = $Log_Model->getLogNum('n', $sqlSegment);
$pageurl = "./?keyword=$slkey&page=";
$logs = $Log_Model->getLogsForHome($sqlSegment, $page, $index_lognum);
$page_url = pagination($lognum, $index_lognum, $page, $pageurl);
}
调用方法:
<form action="./" method="get" enctype="multipart/form-data" onSubmit="return slkeyword();">
<input name="keyword" placeholder="输入货号或者产品名称" />
<button type="submit"/>搜索</button>
</form>