欢迎来到织梦58!我们致力于织梦商业模板及VIP模板更新

织梦58

dede地区联动搜索 彻底解决办法

相关案例演示

本例以文章模型为列子
0 添加 联动类型 地区

plus/search.php
<?php
require_once(dirname(__FILE__)."/include/common.inc.php");
require_once(DEDEINC."/arc.searchview.class.php");

$pagesize = (isset($pagesize) && is_numeric($pagesize)) ? $pagesize : 10;
$typeid = (isset($typeid) && is_numeric($typeid)) ? $typeid : 0;
$nativeplace = (isset($nativeplace) && is_numeric($nativeplace)) ? $nativeplace : 0;
$channeltype = (isset($channeltype) && is_numeric($channeltype)) ? $channeltype : 0;
$kwtype = (isset($kwtype) && is_numeric($kwtype)) ? $kwtype : 1;
$mid = (isset($mid) && is_numeric($mid)) ? $mid : 0;

if(!isset($orderby)) $orderby=”;
else $orderby = eregi_replace(‘[^a-z]‘,”,$orderby);

if(!isset($searchtype)) $searchtype = ‘titlekeyword’;
else $searchtype = eregi_replace(‘[^a-z]‘,”,$searchtype);

if(!isset($keyword)) $keyword = ”;

$oldkeyword = $keyword;

$keyword = FilterSearch(stripslashes($keyword));

//查找栏目信息
if(empty($typeid))
{
    $typenameCacheFile = DEDEROOT.’/data/cache/typename.inc’;
    if(!file_exists($typenameCacheFile) || filemtime($typenameCacheFile) < time()-(3600*24) )
    {
        $fp = fopen(DEDEROOT.’/data/cache/typename.inc’, ‘w’);
        fwrite($fp, "<"."?phprn");
        $dsql->SetQuery("Select id,typename From `ym_arctype`");
        $dsql->Execute();
        while($row = $dsql->GetArray())
        {
            fwrite($fp, "$typeArr[{$row['id']}] = ‘{$row['typename']}’;rn");
        }
        fwrite($fp, ‘?’.'>’);
        fclose($fp);
    }
    //引入栏目缓存并看关键字是否有相关栏目内容
    require_once($typenameCacheFile);
    if(isset($typeArr) && is_array($typeArr))
    {
        foreach($typeArr as $id=>$typename)
        {
            $keywordn = str_replace($typename, ‘ ‘, $keyword);
            if($keyword != $keywordn)
            {
                $keyword = $keywordn;
                $typeid = $id;
                break;
            }
        }
    }
}

$keyword = addslashes(cn_substr($keyword,30));

if($cfg_notallowstr !=” && eregi($cfg_notallowstr,$keyword))
{
    ShowMsg("你的搜索关键字中存在非法内容,被系统禁止!","-1");
    exit();
}

//if(($keyword==” || strlen($keyword)<0) && empty($typeid))
//{
//    ShowMsg(‘关键字不能小于2个字节!’,'-1′);
//    exit();
//}

//检查搜索间隔时间
$lockfile = DEDEROOT.’/data/time.lock.inc’;
if(!file_exists($lockfile)) {
    $fp = fopen($lockfile,’w');
    flock($fp,1);
    fwrite($fp,time());
    fclose($fp);
}

//开始时间
if(empty($starttime)) $starttime = -1;
else
{
    $starttime = (is_numeric($starttime) ? $starttime : -1);
    if($starttime>0)
    {
       $dayst = GetMkTime("2008-1-2 0:0:0") – GetMkTime("2008-1-1 0:0:0");
       $starttime = time() – ($starttime * $dayst);
  }
}

$t1 = ExecTime();

$sp = new SearchView($typeid,$keyword,$orderby,$channeltype,$searchtype,$starttime,$pagesize,$kwtype,$mid,$nativeplace);
$keyword = $oldkeyword;
$sp->Display();

//echo ExecTime() – $t1;
?>

templets/default/search.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{dede:global.cfg_webname/}_搜索结果</title>
<link href="{dede:global.cfg_templeturl/}/style/search.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>

<div class="header">
    <div class="toplogo">
        <h1><a href="{dede:global.cfg_cmsurl/}/">{dede:global.cfg_webname/}</a></h1>
    </div>
    <div class="searchform">
      <form action="{dede:field name=’phpurl’/}/search.php" name="formsearch">
        <div class="s1">搜索</div>
        <div class="s2">
           <input type="hidden" name="kwtype" value="0" />
           <input name="keyword" type="text" class="search-keyword" id="search-keyword" value="{dede:global.keyword/}" />

<input type=’hidden’ id=’hidden_nativeplace’ name=’nativeplace’ value=’0′ />
<span id=’span_nativeplace’></span>
<span id=’span_nativeplace_son’></span>
<script language="javascript" type="text/javascript" src="{dede:global.cfg_indexurl/}/images/enums.js"></script>
<script language=’javascript’ type=’text/javascript’ src=’{dede:global.cfg_indexurl/}/data/enums/nativeplace.js’></script>
<script language="javascript" type="text/javascript">MakeTopSelect("nativeplace", 0);</script>
<input type=’hidden’ name=’dede_addonfields’ value="nativeplace,stepselect">

           <select name="searchtype" class="search-option" id="search-option">
               <option value="titlekeyword" selected=’1′>智能模糊搜索</option>
               <option value="title">仅搜索标题</option>
           </select>
          <button type="submit" class="search-submit">搜索</button>        
        </div>
        </form>
        <div class="s3">
            <a href="heightsearch.php">高级搜索</a>
            <a href="{dede:global.cfg_cmsurl/}/">返回首页</a>
        </div>
    </div>
</div>

<div class="msgbar">
    <p>
        搜索 <strong class="fc_03c">{dede:global name=’keyword’/}</strong> 的结果
    </p>
</div>

<div class="resultlist">
    
{dede:list perpage=’20′}

    <div class="item">
        <h3><a href="[field:arcurl/]" target="_blank">[field:title/]</a></h3>
        <p class="intro">[field:description/]…</p>
        <p class="info">
            <small> 分类:</small><span> <a href="[field:typeurl/]" target="_blank">[field:typename/]</a></span>
            <small>点击:</small><span> [field:click/]</span>
            <small>日期:</small><span> [field:stime/]</span>
        </p>
        <p><span><a href="[field:arcurl/]" target="_blank">[field:arcurl/]</a></span></p>
    </div>
{/dede:list}

</div>

<div class="dede_pages">
    <ul class="pagelist">
        {dede:pagelist listsize=’5′/}  
    </ul>
</div><!– /pages –>

<div class="othersearch">
    <h2>相关搜索:</h2>
    <ul>
        {dede:likewords num=’8′/}
    </ul>
</div>

<div class="footer">
    <p class="link">
        网站版权信息及免责声明
    </p>
    <!–
        为了支持织梦团队的发展,请您保留织梦内容管理系统的链接信息.
        我们对支持织梦团队发展的朋友表示真心的感谢!织梦因您更精彩!
    –>
    <p class="powered">
        Powered by <a href="http://www.千亿国际qy.966.com" title="织梦内容管理系统(千亿国际qy.966)–国内最专业的PHP网站管理系统,轻松建站的首选利器。" target="_blank"><strong>Dede<span>CMS</span></strong></a> ? 2004-2008 DesDev Inc.
    </p><!– /powered –>
    
</div>

</body>
</html> 


EyouCms,简单易用的企业网站管理系统,点击了解更多


有问题可以加入织梦技术QQ群一起交流学习

本站vip会员 请加入织梦58 VIP②群 PS:加入时备注用户名或昵称

普通注册会员或访客 请加入织梦58 技术交流群

作者:DEDE58.COM 关注: 时间:2018-06-29 18:45
首先声明,只要是我们的vip会员所有源码均可以免费下载,不做任何限制(了解更多)
☉本站的源码不会像其它下载站一样植入大量的广告。为了更好的用户体验以后坚持不打水印
☉本站只提供精品织梦源码,源码在于可用,不在多!!希望在这里找到你合适的。
☉本站提供的整站织梦程序,均带数据及演示地址。可以在任一源码详情页查看演示地址
☉本站所有资源(包括源码、模板、素材、特效等)仅供学习与参考,请勿用于商业用途。
☉如有其他问题,请加网站客服QQ(970003436)进行交流。
相关织梦教程
在线客服

×关闭