帝国论坛帝国网站管理系统交流区帝国CMS使用交流多表搜索怎么实现呢? 【本版专题贴子】  
主题:多表搜索怎么实现呢? [加入收藏夹]   

红杏
用户头衔:举人

精华贴   :0
发贴数   :470
经验值   :1645
注册时间:2005-07-27
信息 搜索 好友 发送悄悄话 精益求精-帝国网站管理系统7.5正式版开源发布】   [第 1 楼]
多表搜索怎么实现呢?
RT

搞不定。3Q

<input type="hidden" name="classid" value="1,2,3,4,5,6">

这样好像不行哈。

[该贴被修改 1 次,最后修改时间 2007-01-15 16:14:34 ]


数据转换:你的系统转到帝国! ^_^
插件开发:定制帝国插件。
详情qq:3682335
2007-01-15 16:10:54 已设置保密 顶部 回复 引用 报告 编辑 删除

wm_chief
用户头衔:管理员

精华贴   :21
发贴数   :48941
经验值   :114161
注册时间:2002-10-30
信息 搜索 好友 发送悄悄话 免费开源-EBMA系统:更安全的MYSQL管理和备份系统】   [第 2 楼]

只能搜索其中一个表



[零基础入门教程] [模板制作教程] [采集使用教程]
2007-01-15 16:15:34 已设置保密 顶部 回复 引用 报告 编辑 删除

红杏
用户头衔:举人

精华贴   :0
发贴数   :470
经验值   :1645
注册时间:2005-07-27
信息 搜索 好友 发送悄悄话 精益求精-帝国网站管理系统7.5正式版开源发布】   [第 3 楼]

我分了几个表,这下麻烦了。。
55555555555555555

开动脑筋!

改!




数据转换:你的系统转到帝国! ^_^
插件开发:定制帝国插件。
详情qq:3682335
2007-01-15 16:19:25 已设置保密 顶部 回复 引用 报告 编辑 删除

沉默是金
用户头衔:秀才

精华贴   :0
发贴数   :88
经验值   :498
注册时间:2007-09-10
信息 搜索 好友 发送悄悄话 免费开源-EBMA系统:更安全的MYSQL管理和备份系统】   [第 4 楼]

能不能做一个多表搜索的表单啊..




2007-11-25 15:47:40 已设置保密 顶部 回复 引用 报告 编辑 删除

sqhcm
用户头衔:书生

精华贴   :0
发贴数   :12
经验值   :79
注册时间:2007-09-10
信息 搜索 好友 发送悄悄话 精益求精-帝国网站管理系统7.5正式版开源发布】   [第 5 楼]

关于多表搜索解决!
重新构建一个搜索php(index1.php和result/index1.php)
把需要多表搜索的action指向index1.php其它指向默认index.php
我这个里只能按标题,作者,时间,简介这几字段并且是没有info,movie,shop,photo这个表内容,如需要请自己加入

请大家支持我的网站一下,www.xcpet.com
index1.php见如下内容:
<?php
require("../class/connect.php");
include("../class/db_sql.php");
include("../class/config.php");
include("../class/class.php");
include("../class/q_functions.php");
$link=db_connect();
$empire=new mysqlquery();
$ip=egetip();
$searchtime=time();
$getvar=$_POST['getvar'];
if(empty($getvar))
{
        $getfrom="history.go(-1)";
}
else
{
        $getfrom="../../search";
        $dogetvar="&getvar=1";
}
//搜索用户组
if($public_r['searchgroupid'])
{
        $psearchgroupid=$public_r['searchgroupid'];
        @include("../class/MemberLevel.php");
        $searchgroupid=(int)getcvar('mlgroupid');
        if($level_r[$searchgroupid][level]<$level_r[$psearchgroupid][level])
        {
                printerror("NotLevelToSearch",$getfrom,1);
        }
}
$add="";
$addprice="";
$keyboard=trim($_POST['keyboard']);
$s_tbname=RepPostVar($_POST['tbname']);
$s_tempid=(int)$_POST['tempid'];
$classid=(int)$_POST['classid'];
$searchclass=$_POST['show'];
$myorder=(int)$_POST['myorder'];
$orderby=(int)$_POST['orderby'];
$starttime=RepPostVar($_POST['starttime']);
if(empty($starttime))
{$starttime="0000-00-00";}
$endtime=RepPostVar($_POST['endtime']);
if(empty($endtime))
{$endtime="0000-00-00";}
$startprice=(int)$_POST['startprice'];
$endprice=(int)$_POST['endprice'];
//搜索间隔
$lastsearchtime=getcvar('lastsearchtime');
if($lastsearchtime)
{
        if($searchtime-$lastsearchtime<$public_r[searchtime])
        {printerror("SearchOutTime",$getfrom,1);}
}
$len=strlen($keyboard);
if(empty($keyboard))
{printerror("EmptyKeyboard",$getfrom,1);}
//关键字限制
if($len<$public_r[min_keyboard]||$len>$public_r[max_keyboard])
{printerror("MinKeyboard",$getfrom,1);}
$keyboard=addslashes(stripSlashes($keyboard));
//时间范围
if($endtime!="0000-00-00")
{
        $starttimea=$starttime." 00:00:00";
        $endtimea=$endtime." 11:59:59";
        $add=" and newstime>='$starttimea' and newstime<='$endtimea'";
}
//价格
if($endprice)
{
        $addprice=" and price>=".$startprice." and price<=".$endprice;
}
if($classid)
{
        //终极栏目
        if($class_r[$classid][islast])
        {
                $add.=" and classid='$classid'";
        }
        else
        {
                $where=ReturnClass($class_r[$classid][sonclass]);
                $add.=" and (".$where.")";
        }
        $tbname=$class_r[$classid][tbname];
        $modid=$class_r[$classid][modid];
}
elseif($s_tbname)
{

        $tbnamenum=$empire->gettotal("select count(*) as total from {$dbtbpre}enewstable where tbname='$s_tbname' limit 1");
        if(!$tbnamenum)
        {
                Header("Location:result/index1.php?searchid=0".$dogetvar);
                exit();
        }
//修改此处的表
        $tbname=" (select classid,newspath,filename,title,newstime,checked,smalltext,writer from xcpetecms_news  union select classid,newspath,filename,title,newstime,checked,softsay as smalltext,softwriter as writer from xcpetecms_download union select classid,newspath,filename,title,newstime,checked,flashsay as smalltext,flashwriter as writer from xcpetecms_flash union  select classid,newspath,filename,title,newstime,checked,smalltext,writer from xcpetecms_article) a  ";
        //$tbname=$s_tbname;
        //模型id
        $thestemp_r=$empire->fetch1("select modid from ".GetTemptb("enewssearchtemp")." where tempid='$s_tempid'");
        if(empty($thestemp_r['modid']))
        {
                Header("Location:result/index1.php?searchid=0".$dogetvar);
                exit();
        }
        $modid=$thestemp_r['modid'];
}
else
{
//修改此处的表
        $tbname=" (select classid,newspath,filename,title,newstime,checked,smalltext,writer from xcpetecms_news  union select classid,newspath,filename,title,newstime,checked,softsay as smalltext,softwriter as writer from xcpetecms_download union select classid,newspath,filename,title,newstime,checked,flashsay as smalltext,flashwriter as writer from xcpetecms_flash union  select classid,newspath,filename,title,newstime,checked,smalltext,writer from xcpetecms_article) a  ";

        //$tbname=$public_r['tbname'];
}
//表不存在
if(empty($tbname))
{
        Header("Location:result/index1.php?searchid=0".$dogetvar);
        exit();
}
//搜索字段
if(empty($searchclass)||strstr($searchclass," "))
{
        Header("Location:result/index1.php?searchid=0".$dogetvar);
        exit();
}
//取得字段
if(empty($class_r[$classid][searchtempid]))
{
        if(empty($modid))
        {
                $tempr=$empire->fetch1("select modid from ".GetTemptb("enewssearchtemp")." where isdefault=1 limit 1");
        }
        else
        {
                $tempr[modid]=$modid;
        }
}
else
{
        $tempr[modid]=$modid;
        //$tempr=$empire->fetch1("select modid from ".GetTemptb("enewssearchtemp")." where tempid='".$class_r[$classid][searchtempid]."' limit 1");
}
//完全
$asame="";
$sfsql=" like '%[!--key--]%'";
if($_POST['allsame']==1)
{
        $asame=1;
        $sfsql="='[!--key--]'";
}
$mr=$empire->fetch1("select searchvar,tbname from {$dbtbpre}enewsmod where mid='$tempr[modid]'");
$fr=explode(",",$searchclass);
$sf="";
for($j=0;$j<count($fr);$j++)
{
        //验证参数是否正确
        if(!strstr($mr[searchvar],",".$fr[$j].","))
        {
                continue;
        }
        if(empty($newsearchclass))
        {
                $or="";
                $dh="";
        }
        else
        {
                $or=" or ";
                $dh=",";
        }
        $newsearchclass.=$dh.$fr[$j];
        $sf.=$or.$fr[$j].$sfsql;
}
$searchclass=$newsearchclass;
//是否包含价格
if(!strstr($mr[searchvar],",price,"))
{
        $addprice="";
        $startprice=0;
        $endprice=0;
}
//参数错
if(empty($sf))
{
        Header("Location:result/index1.php?searchid=0".$dogetvar);
        exit();
}
//---------------多个关键字
$kr=explode(" ",$keyboard);
for($i=0;$i<count($kr);$i++)
{
        if(empty($kr[$i]))
        {continue;}
        $add.=" and (".str_replace("[!--key--]",$kr[$i],$sf).")";
}
//验证码
if($s_tempid)
{
        $mtempid=$s_tempid;
}
else
{
        $mtempid="";
}
$checkpass=md5($keyboard.$searchclass.$classid.$starttime.$endtime.$startprice.$endprice.$s_tbname.$mtempid.$asame);
$search_r=$empire->fetch1("select searchid,searchtime from {$dbtbpre}enewssearch where checkpass='$checkpass' limit 1");
$todaytime=date("Y-m-d H:i:s");
$query="select count(*) as total from ".$tbname." where checked=1".$add.$addprice;
$searchid=$search_r[searchid];
//是否有历史记录
if($searchid)
{
    $search_num=$empire->gettotal($query);
        $sql=$empire->query("update {$dbtbpre}enewssearch set searchtime=$searchtime,result_num=$search_num,onclick=onclick+1,orderby=$orderby,myorder=$myorder,tempid=$s_tempid,allsame='$asame' where searchid='$searchid'");
        if(empty($search_num))
        {$searchid=0;}
}
else
{
        $search_num=$empire->gettotal($query);
        if(empty($search_num))
        {$searchid=0;}
        else
        {
                $sql=$empire->query("insert into {$dbtbpre}enewssearch(searchtime,keyboard,searchclass,result_num,searchip,classid,onclick,orderby,myorder,starttime,endtime,startprice,endprice,checkpass,tbname,tempid,allsame) values($searchtime,'$keyboard','$searchclass',$search_num,'$ip',$classid,1,$orderby,$myorder,'$starttime','$endtime',$startprice,$endprice,'$checkpass','$s_tbname',$s_tempid,'$asame')");
                $searchid=$empire->lastid();
        }
}
//设置最后搜索时间
$set1=esetcookie("lastsearchtime",$searchtime,$searchtime+3600*24);
db_close();
$empire=null;
Header("Location:result/index1.php?searchid=$searchid".$dogetvar);
?>

result/index1.php内容如下:

<?php
require("../../class/connect.php");
include("../../class/db_sql.php");
include("../../class/config.php");
include("../../class/class.php");
include("../../class/q_functions.php");
include "../".LoadLang("pub/fun.php");
$editor=1;
$link=db_connect();
$empire=new mysqlquery();
$getvar=$_GET['getvar'];
if(empty($getvar))
{
        $getfrom="history.go(-1)";
}
else
{
        $getfrom="../../../search";
}
//搜索结果
$searchid=(int)$_GET['searchid'];
if(empty($searchid))
{printerror("SearchNotRecord",$getfrom,1);}
$page=(int)$_GET['page'];
$start=(int)$_GET['start'];
$search="&searchid=".$searchid;
$add="";
$page_line=$public_r['search_pagenum'];//每页显示链接数
$line=$public_r['search_num'];//每页显示记录数
$offset=$start+$page*$line;//总偏移量
$search_r=$empire->fetch1("select searchid,keyboard,result_num,classid,searchclass,orderby,myorder,starttime,endtime,startprice,endprice,tbname,tempid,allsame from {$dbtbpre}enewssearch where searchid='$searchid'");
if(empty($search_r['searchid']))
{printerror("SearchNotRecord",$getfrom,1);}
//时间范围
if($search_r[endtime]!="0000-00-00")
{
        $starttime=$search_r[starttime]." 00:00:00";
        $endtime=$search_r[endtime]." 11:59:59";
        $add=" and newstime>='$starttime' and newstime<='$endtime'";
}
//价格
if($search_r[endprice])
{
        $add.=" and price>=".$search_r[startprice]." and price<=".$search_r[endprice];
}
$have_class=1;
if($search_r[classid])
{
        //终极栏目
        if($class_r[$search_r[classid]][islast])
        {
                $add.=" and classid='$search_r[classid]'";
                $have_class=0;
        }
        else
        {
                $where=ReturnClass($class_r[$search_r[classid]][sonclass]);
                $add.=" and (".$where.")";
        }
        $tbname=$class_r[$search_r[classid]][tbname];
        $modid=$class_r[$search_r[classid]][modid];
}
elseif($search_r['tbname'])
{
//修改此处的表
        $tbname=" (select classid,newspath,filename,title,newstime,checked,smalltext,writer from xcpetecms_news  union select classid,newspath,filename,title,newstime,checked,softsay as smalltext,softwriter as writer from xcpetecms_download union select classid,newspath,filename,title,newstime,checked,flashsay as smalltext,flashwriter as writer from xcpetecms_flash union  select classid,newspath,filename,title,newstime,checked,smalltext,writer from xcpetecms_article) a  ";
}
else
{
//修改此处的表
        $tbname=" (select classid,newspath,filename,title,newstime,checked,smalltext,writer from xcpetecms_news  union select classid,newspath,filename,title,newstime,checked,softsay as smalltext,softwriter as writer from xcpetecms_download union select classid,newspath,filename,title,newstime,checked,flashsay as smalltext,flashwriter as writer from xcpetecms_flash union  select classid,newspath,filename,title,newstime,checked,smalltext,writer from xcpetecms_article) a  ";
}
//完全
$sfsql=" like '%[!--key--]%'";
if($search_r['allsame'])
{
        $sfsql="='[!--key--]'";
}
//搜索字段
$fr=explode(",",$search_r[searchclass]);
$searchfield=$search_r[searchclass];
for($j=0;$j<count($fr);$j++)
{
        if($j==0)
        {$or="";}
        else
        {$or=" or ";}
        $sf.=$or.$fr[$j].$sfsql;
}
//---------------多个关键字
$kr=explode(" ",$search_r[keyboard]);
$keyboard=$search_r[keyboard];
for($i=0;$i<count($kr);$i++)
{
        if(empty($kr[$i]))
        {continue;}
        $add.=" and (".str_replace("[!--key--]",$kr[$i],$sf).")";
}
if($search_r[orderby]==1)//信息ID
{$myorder="id";}
elseif($search_r[orderby]==2)//评论数
{$myorder="plnum";}
elseif($search_r[orderby]==3)//点击率
{$myorder="onclick";}
elseif($search_r[orderby]==4)//下载数
{$myorder="totaldown";}
else//时间
{$myorder="newstime";}
if(empty($search_r[myorder]))
{$myorder.=" desc";}
//当前时间
$todaytime=date("Y-m-d H:i:s");
$query="select * from ".$tbname." where checked=1".$add;
$num=$search_r[result_num];
$query.=" order by ".$myorder." limit $offset,$line";
$sql=$empire->query($query);
$listpage=page1($num,$line,$page_line,$start,$page,$search);
//取得模板
if($search_r['tempid'])
{
        $tempr=$empire->fetch1("select temptext,subnews,listvar,rownum,showdate,modid,subtitle from ".GetTemptb("enewssearchtemp")." where tempid='".$search_r['tempid']."' limit 1");
}
elseif(empty($class_r[$search_r[classid]][searchtempid]))
{
        $tempr=$empire->fetch1("select temptext,subnews,listvar,rownum,showdate,modid,subtitle from ".GetTemptb("enewssearchtemp")." where isdefault=1 limit 1");
}
else
{
        $tempr=$empire->fetch1("select temptext,subnews,listvar,rownum,showdate,modid,subtitle from ".GetTemptb("enewssearchtemp")." where tempid='".$class_r[$search_r[classid]][searchtempid]."' limit 1");
}
//替换公共模板变量
$listtemp=$tempr[temptext];
if($public_r['searchtempvar'])
{
        $listtemp=ReplaceTempvar($listtemp);
}
$listtemp=str_replace("[!--show.page--]",$listpage,stripSlashes($listtemp));
$listtemp=str_replace("[!--keyboard--]",$keyboard,$listtemp);
$listtemp=str_replace("[!--ecms.num--]",$num,$listtemp);
$listtemp=str_replace("[!--news.url--]",$public_r[newsurl],$listtemp);
$listtemp=str_replace("[!--pagetitle--]",$fun_r['adsearch'],$listtemp);
$rownum=$tempr[rownum];
if(empty($rownum))
{$rownum=1;}
$formatdate=$tempr[showdate];
$subnews=$tempr[subnews];
$subtitle=$tempr[subtitle];
$modid=$tempr[modid];
$listvar=stripSlashes($tempr[listvar]);
//字段
$ret_r=ReturnAddF($tempr[modid],2);
$field=$ret_r[0];
//取得列表模板
$list_exp="[!--empirenews.listtemp--]";
$list_r=explode($list_exp,$listtemp);
$listtext=$list_r[1];
$no=$offset;
$changerow=1;
while($r=$empire->fetch($sql))
{
        //替换列表变量

$r[title]=str_replace($search_r[keyboard],"<font color='red'><B>$search_r[keyboard]</B></font>",$r[title]);
$r[smalltext]=str_replace($search_r[keyboard],"<font color='red'><B>$search_r[keyboard]</B></font>",$r[smalltext]);
        $repvar=ReplaceListVars($no,$listvar,$subnews,$subtitle,$formatdate,$url,$have_class,$r,$field);
        $listtext=str_replace("<!--list.var".$changerow."-->",$repvar,$listtext);
        $changerow+=1;
        //超过行数
        if($changerow>$rownum)
        {
                $changerow=1;
                $string.=$listtext;
                $listtext=$list_r[1];
        }
        $no++;
}
db_close();
$empire=null;
//多余数据
if($changerow<=$rownum&&$listtext<>$list_r[1])
{
        $string.=$listtext;
}
$string=$list_r[0].$string.$list_r[2];
echo $string;
?>



学生课堂在线 欢迎各位光临
2008-01-30 17:00:44 已设置保密 顶部 回复 引用 报告 编辑 删除

sqhcm
用户头衔:书生

精华贴   :0
发贴数   :12
经验值   :79
注册时间:2007-09-10
信息 搜索 好友 发送悄悄话 免费开源-EBMA系统:更安全的MYSQL管理和备份系统】   [第 6 楼]

这个是4.7的多表搜索,解压到,E目录下:

上传以下附件:
[下载 *.rar](文件大小:8.38 KB,下载次数:76)



学生课堂在线 欢迎各位光临
2008-05-14 14:19:20 已设置保密 顶部 回复 引用 报告 编辑 删除

mydream
用户头衔:进士 *

精华贴   :0
发贴数   :384
经验值   :2109
注册时间:2007-12-27
信息 搜索 好友 发送悄悄话 精益求精-帝国网站管理系统7.5正式版开源发布】   [第 7 楼]

原帖由 sqhcm 于 2008-05-14 14:19:20 发表
这个是4.7的多表搜索,解压到,E目录下:


收藏,谢谢分享!




2008-05-14 17:11:42 已设置保密 顶部 回复 引用 报告 编辑 删除

hicode
用户头衔:版主

精华贴   :1
发贴数   :21646
经验值   :47915
注册时间:2007-07-20
信息 搜索 好友 发送悄悄话 免费开源-EBMA系统:更安全的MYSQL管理和备份系统】   [第 8 楼]

原帖由 sqhcm 于 2008-05-14 14:19:20 发表
这个是4.7的多表搜索,解压到,E目录下:

支持下




2008-05-14 17:14:51 已设置保密 顶部 回复 引用 报告 编辑 删除

快速回复
内容

表情
使用EBB代码 使用smile代码 显示签名 自动分析url 自动分析img
     【进入高级模式】   (按 Ctrl+Enter 直接提交)
    顶部  加入收藏夹
关于帝国 | 广告服务 | 联系我们 | 法律声明 | 隐私条款 | 许可协议
Powered by: EBB Version 2.2.1