什么搜索代码啊?
是搜索整个Internet
还是只搜索自己的网站啊?
或者只搜索自己网站的数据库?

解决方案 »

  1.   

    楼主的意思可能是:
    支持and or等关键字
      

  2.   

    to  print(小生):搜索自己的网站和搜索网站的数据库还是有区别的
    不用数据库当然可以搜索————直接搜索文件啊
      

  3.   

    re vivanboy(雍亲王)是呀有OR AND 搜索的谁有呀
      

  4.   

    我有,给你了
    search.php<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD><TITLE>图书搜索</TITLE>
    <META content="text/html; charset=gb2312" http-equiv=Content-Type></HEAD>
    <? require("index.html.inc") ?>
    <BODY>
    <TABLE>
    <TBODY>
    <TR>
            <TD valign=top width="30%" bgcolor=8cc9ec>
            <TABLE>
            <TBODY>
                    <TR><TD colspan=2>查询页使用说明:</TD></TR>
                    <TR><TD valign=top>1.</TD><TD>查询时可以使用“and”或“or”逻辑词,逻辑词个数不限,暂不支持同时使用。</TD></TR>
                    <TR><TD valign=top>2.</TD><TD>注意查询条件的中关键词的合理顺序。</TD></TR>
                    <TR><TD valign=top>3.</TD><TD>可以控制查询结果的输出个数。</TD></TR>
                    <TR><TD valign=top>4.</TD><TD>出版日期请使用“年-月-日”的格式。</TD></TR>
                    <TR><TD valign=top>5.</TD><TD>如果填写了ISBN,则将忽略其它条件。</TBODY></TABLE>
            <TD valign=top width="70%">
            <FORM action=search2.php method=post>
            <TABLE width="100%" border=1 bgcolor=#8cc9ec>
            <TBODY>
                    <TR><TD align=center width="35%">&nbsp;&nbsp;ISBN&nbsp;&nbsp;</TD><TD><input type=text name=isbn size=10></TD></TR>
                    <TR><TD align=center width="35%">书&nbsp;&nbsp;&nbsp;&nbsp;名</TD><TD><input type=text name=title size=25></TD></TR>
                    <TR><TD align=center width="35%">作&nbsp;&nbsp;&nbsp;&nbsp;者</TD><TD><input type=text name=author size=25></TD></TR>
                    <TR><TD align=center width="35%">出&nbsp;&nbsp;版&nbsp;&nbsp;社</TD><TD><input type=text name=publisher size=25></TD></TR>
                    <TR><TD align=center width="35%">出&nbsp;版&nbsp;日&nbsp;期</TD><TD><input type=text name=downdate size=11> - <input type=text name=update size=11></TD></TR>
                    <TR><TD align=center width="35%">查询结果限制在(个)</TD><TD><input type=text name=limit size=11></TD>
                    <TR><TD>&nbsp;&nbsp;请选择你想查找哪一类图书</TD><TD>
                            <select class=input size=1 name=cata>
                            <option value=0 selected>--选 择--</option>
                            <option value=1000>文学艺术类</option>
                            <option value=2000>社会科学类</option>
                            <option value=3000>科学技术类</option>
                            <option value=4000>教育类</option>
                            <option value=5000>生活类</option>
                            <option value=6000>工具书类</option></select></TD></TR>
                    <TR><TD colspan=2 align=center><input type=submit name=find2 value=开始查询>&nbsp;&nbsp;<input type=reset width=10 value=重填表格></TD></TR>
            </TBODY></TABLE></FORM></TD></TR>
    </TBODY></TABLE>
    </BODY>
    <? require("foot.html.inc") ?>
    </HTML>
      

  5.   

    search2.php分几部分给你了。
    1、前100行<?
    function parse($option,$class) {
            $arr=explode("or",$option);
            $logic="or";
            if( count($arr)==1 ) {
                    $arr=explode("and",$option);
                    $logic="and";
            }
            $num=count($arr);
            for($i=0;$i<$num;$i++) {
                    $arr[$i]=trim(chop($arr[$i]));
            }
            if( !strcmp($class,"update") ) {
                    return " publishday<\"$arr[0]\" ";
            }else if( !strcmp($class,"downdate") ) {
                    return " publishday>\"$arr[0]\" ";
            }else if( !strcmp($class,"isbn") ) {
                    return " isbn=$arr[0] ";
            }else if( !strcmp($class,"limit") ) {
                    return " limit $arr[0]";
            }else if( !strcmp($class,"title") ) {
                    if( count($arr)==1 ) {
                            return " title like \"%".$arr[0]."%\"";
                    }else {
                            $query=" title like ";
                            if( !strcmp($logic,"and") ) {
                                    $query="$query\"%";
                                    for($i=0;$i<count($arr);$i++) {
                                            $query=$query."$arr[$i]%";
                                    }
                                    $query="$query\"";
                            }else {
                                    $query=$query."\"%".$arr[0]."%\" ";
                                    for($i=1;$i<count($arr);$i++) {
                                            $query=$query."or \"%".$arr[$i]."%\"";
                                    }
                            }
                            return $query;
                    }
            }else if( !strcmp($class,"publisher") ) {
                    if( count($arr)==1 ) {
                            return " fullname like \"%".$arr[0]."%\"";
                    }else {
                            $query=" fullname like ";
                            if( !strcmp($logic,"and") ) {
                                    $query="$query\"%";
                                    for($i=0;$i<count($arr);$i++) {
                                            $query=$query."$arr[$i]%";
                                    }
                                    $query="$query\"";
                            }else {
                                    $query=$query."\"%".$arr[0]."%\" ";
                                    for($i=1;$i<count($arr);$i++) {
                                            $query=$query."or \"%".$arr[$i]."%\"";
                                    }
                            }
                            return $query;
                    }
            }else if( !strcmp($class,"author") ) {
                    if( count($arr)==1 ) {
                            return " author like \"%$arr[0]%\" ";
                    }else {
                            $query=" author like ";
                            if( !strcmp($logic,"and") ) {
                                    $query="$query\"%";
                                    for($i=0;$i<count($arr);$i++) {
                                            $query=$query."$arr[$i]%";
                                    }
                                    $query="$query\"";
                            }else {
                                    $query=$query."\"%".$arr[0]."%\" ";
                                    for($i=1;$i<count($arr);$i++) {
                                            $query=$query."or \"%$arr[$i]%\" ";
                                    }
                            }
                            return $query;
                    }
            }else if( !strcmp($class,"cata") ) {
                    return " class>$arr[0] and class<".($arr[0]+1000)." ";
            }
    }
    function conndb() {
            $db=mysql_connect("localhost","root","");
            if( $db==false ) {
                    print "Database failed!";
                    exit();
            }
            return $db;
    }
    function resultempty($cata,$option) {
            print "<TR><TD align=center>你的查询条件为 <FONT COLOR=#CC0066>$cata = $option</FONT></TD></TR>";
            print "<TR><TD align=center>数据库中没有满足条件的记录!</TD></TR>";
    }
    function result($query,$from,$total,$limit) {
            $db=conndb();
            print "<TR><TD colspan=2 align=center>你的查询条件为 <FONT COLOR=#CC0066>$query[0] ";
            if( !empty($limit) ) {
                    print "limit $limit";
            }
            print "</FONT></TD></TR>";
      

  6.   

    2、101——200:if( $total==0 ) {
                    print "<TR><TD colspan=2 align=center>数据库中没有满足条件的记录!</TD></TR>";
            }else {
                    if( !empty($limit) ) {
                            $min=$limit>$total?$total:$limit;
                    }else {
                            $min=$total;
                    }
                    $step=($min-$from>15)?15:$min-$from;
                    $res=mysql_db_query("bookseller","$query[0] limit $from,$step",$db);
                    print "<TR><TD colspan=2>当前记录 $from - ".($from+$step-1)." (共有记录 $total,显示 $min)";
                    for($i=0;$i<$step;$i++) {
                            $row=@mysql_fetch_row($res);
                            print "<TR><TD><A href=\"details.php?isbn=$row[0]\">$row[1]</A><TD>$row[2]</TD></TR>\n";
                    }
                    if( $step<$min) {
                            print "<TR><TD colspan=2><A href=\"$PHP_SELF?query=$query&from=0&total=$total&limit=$limit\"><FONT color=#CC0066>首页</FONT></A>&nbsp;&nbsp;";
                    }
                    if( $from>=2*15 ) {
                            print "<A href=\"$PHP_SELF?query='$query'&from=".($from-15)."&total=$total&limit=$limit\"><FONT color=#CC0066>上一页</FONT></A>&nbsp;&nbsp;";
                    }
                    if( ($min-$from-15)>0 ) {
                            print "<A href=\"$PHP_SELF?query=$query&from=".($from+15)."&total=$total&limit=$limit\"><FONT color=#CC0066>下一页</FONT></A>&nbsp;&nbsp;";
                    }
                    if( ($from+2*15)<=$min ) {
                            print "<A href=\"$PHP_SELF?query=$query&from=".($from+$step)."&total=$total&limit=$limit\"><FONT color=#CC0066>末页</FONT></A>&nbsp;&nbsp;";
                    }
                    print "</TD></TR>\n";
            }
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD><TITLE>搜索结果</TITLE>
    <META content="text/html; charset=gb2312" http-equiv=Content-Type></HEAD>
    <? require("index.html.inc"); ?>
    <BODY>
    <TABLE width="70%" align=center bgcolor=#8cc9ec border=1>
    <TBODY>
    <?
            for($i=0,$j=0;$i<count($HTTP_POST_VARS);$i++) {
                    $var=each($HTTP_POST_VARS);
                    if( empty($var[1]) )
                            $j++;
            }
            if( $j==count($HTTP_POST_VARS)-1 ) {
                    print "<TABLE align=center><TBODY><TR><TD align=center><FONT size=4 color=#CC0066>查询条件不能为空!<BR>请填入完整的查询条件然后再开始查询,谢谢合作!</FONT></TD></TR></TBODY></TABLE>";
            }else if( isset($from) ) {
                    result($query,$from,$total,0);
            }else if( isset($find1) ) {
                    $db=conndb();
                    if( !empty($option) ) {
                            if( empty($optionid) ) {
                                    $optionid=1;
                            }
                            $query="select isbn,title,author from books where ";
                            switch($optionid) {
                                    case 1:
                                            $s=parse($option,"title");
                                            $query=$query.$s;
                                            $res=@mysql_db_query("bookseller",$query,$db);
                                            if( @mysql_num_rows($res)==0 ) {
                                                    resultempty("书名",$option);
                                            }else {
                                                    $array[0]=$query;
                                                    $num=mysql_num_rows($res);
                                                    result($array,0,$num,0);
                                            }
                                            break;
                                    case 2:
                                            $s=parse($option,"author");
                                            $query=$query.$s;
                                            $res=@mysql_db_query("bookseller",$query,$db);
                                            if( @mysql_num_rows($res)==0 ) {
                                                    resultempty("作者",$option);
                                            }else {
                                                    $array[0]=$query;
                                                    $num=mysql_num_rows($res);
                                                    result($array,0,$num,0);
                                            }
                                            break;
                                    case 3:
                                            $s=parse($option,"isbn");
                                            $query=$query.$s;
                                            $res=@mysql_db_query("bookseller",$query,$db);
                                            if( @mysql_num_rows($res)==0 ) {
                                                    resultempty("ISBN",$option);
                                            }else {
                                                    $array[0]=$query;
                                                    $num=mysql_num_rows($res);
                                                    result($array,0,$num,0);
                                            }
                                            break;
                                    case 4:
                                            $s=parse($optoin,"publisher");
                                            $query="select id from publisher where $s";
                                            $res=@mysql_db_query("bookseller",$query,$db);
                                            $query="select isbn,title,author from books where publisher in (";
                                            if( @mysql_num_rows($res)!=0 ) {
                                                    $row=@mysql_fetch_row($res);
                                                    $query="$query $rows[0],";
      

  7.   

    要是or and 能一起用就好了。。还谁有呀。。分会加的
      

  8.   

    To cnnps(诸葛晓光):
    你有好多帖子都没结分嘛,呵呵,这个程序我写过,不过我暂时还没找到,明天或者后天给你!
      

  9.   

    for($i=1;$i<@mysql_num_rows($res);$i++) {
                                                            $row=@mysql_fetch_row($res);
                                                            $query="$query ,$row[0]";
                                                    }
                                                    $query="$query )";
                                                    $res=@mysql_db_query("bookseller",$query,$db);
                                                    if( ($num=@mysql_num_rows($res))!=0 ) {
                                                            $array[0]=$query;
                                                            result($array,0,$num,0);
                                                    }else {
                                                            resultempty("出版社",$option);
                                                    }
                                            }else {
                                                    resultempty("出版社",$option);
                                            }
                                            break;
                            }
                    }else {
                            print "<TABLE align=center><TBODY><TR><TD align=center><FONT size=4 color=#CC0066>请输入查询条件!</TD></TR></TBODY></TABLE>\n";
                    }
            }else {
                    $db=conndb();
                    $query="select isbn,title,author from books where ";
                    if( !empty($isbn) ) {
                            $query="select title,author from books where ";
                            $a=parse($isbn,"isbn");
                            if( !empty($limit) ) {
                                    $b=parse($limit,"limit");
                                    $query="$query $a $b";
                            }else {
                                    $query=$query.$a;
                            }
                            if( !empty($limit) ) {
                                    $limitted=parse($limit,"limit");
                            }
                            $res=mysql_db_query("bookseller",$query." $limitted",$db);
                            $num=mysql_num_rows($res);
                            $array[0]=$query;
                            result($array,0,$num,$limit);
                    }else {
                            $a;
                            if( !empty($title) ) {
                                    $a=parse($title,"title");
                            }
                            if( !empty($author) ) {
                                    if( !empty($a) ) {
                                            $a="$a and ".parse($author,"author");
                                    }else {
                                            $a=parse($author,"author");
                                    }
                            }
                            if( !empty($downdate) ) {
                                    if( !empty($a) ) {
                                            $a="$a and ".parse($downdate,"downdate");
                                    }else {
                                            $a=parse($downdate,"downdate");
                                    }
                            }
                            if( !empty($update) ) {
                                    if( !empty($a) ) {
                                            $a="$a and ".parse($update,"update");
                                    }else {
                                            $a=parse($update,"update");
                                    }
                            }
                            if( !empty($publisher) ) {
                                    $b=parse($publisher,"publisher");
                                    $qry="select id from publishers where $b;";
                                    $res=@mysql_db_query("bookseller",$qry,$db);
                                    if( $res==false||@mysql_num_rows($res)==0 ) {
                                            print "<TABLE align=center><TBODY><TR><TD align=center><FONT size=4 color=#CC0066>你的查询条件为 出版社 = $publisher<BR>在数据库中找不到相关记录!</TD></TR></TBODY></TABLE>\n";
                                            require("foot.html.inc");
                                            exit();
                                    }
                                    $b=" publisher in (";
                                    for($i=0;$i<@mysql_num_rows($res)-1;$i++) {
                                            $row=@mysql_fetch_row($res);
                                            $b="$b$row[0],";
                                    }
                                    $row=@mysql_fetch_row($res);
                                    $b="$b$row[0]) ";
                                    if( !empty($a) ) {
                                            $a=" $a and $b ";
                                    }else {
                                            $a=$b;
                                    }
                            }
                            if( !empty($cata) ) {
                                    if( !empty($a) ) {
                                            $a="$a and ".parse($cata,"cata");
                                    }else {
                                            $a=parse($cata,"cata");
                                    }
                            }
                            $limitted;
                            if( !empty($limit) ) {
                                    if( empty($a) ) {
                                            print "<TABLE align=center><TBODY><TR><TD align=center><FONT size=4 color=#CC0066>你还需要指定一些其他条件!</TD></TR></TBODY></TABLE>\n";
                                            require("foot.html.inc");
                                            exit();
                                    }
                                    $limitted=parse($limit,"limit");
                            }
                            $query="$query $a";
                            $res=mysql_db_query("bookseller",$query,$db);
                            $num=mysql_num_rows($res);
                            $array[0]=$query;
                            result($array,0,$num,$limit);
                    }
            }
    ?>
    </TBODY></TABLE>
    </BODY>
    <? require("foot.html.inc") ?>
    </HTML>
      

  10.   

    把你的E-mail留下,具体实例请到http://www.gongan.ningbo.gov.cn/,点高级搜索看看是不是你想要的那种效果!
      

  11.   

    如果哪位兄弟也想要的话,请留下E-mail,我会一一发的。
      

  12.   

    [email protected]~!~!~!只作参考~!~!~!
      

  13.   

    [email protected]
    谢谢!
      

  14.   

    我也要!
    [email protected]
    3x先!
      

  15.   

    我也要啊
    [email protected]
    谢谢!
      

  16.   

    我已经写了一篇文档,地址如下:
    http://www.csdn.net/expert/topic/997/997314.xml?temp=.2075617
    E-mail我就不发了。呵呵