0

你好我想问一个问题,现在我开始使用搜索引擎,所以你能建议一些功能或方法如何开始或使用什么来通过用户名从数据库用户制作搜索引擎。它可以搜索用另一个词的一个符号我写“k”,然后它搜索所有以用户名“k”开头的用户名。示例: http: //postimg.org/image/sg84ny3w3/

试过:

private function Search()
{
    global $database;

    if(isset($_POST['s'])) {
        if($_POST['s'] == '1' || $_POST['s'] == '2' || $_POST['s'] == '3')
            $type = $_POST['s'];
        $database->getSearchData($type, $_POST['xs']);
        }

    else if(!preg_match("/[^0-9A-Za-z]/", $_POST['xs'])){
        $error = "You entered invalid data";
        }

        return false;
}

html:

<div id="content">
<div style="padding:20px">
<?echo $error;?>
    <form action="index.php?mod=highscore&t=search"  method="POST" accept-charset="utf-8">
    <div class="title_box"><div class="title_inner">
            What are you searching for?     </div></div>
        <div class="title2_box"><div class="title2_inner">
        <p>
            <table width="80%">
                <tr>
                    <td><input type="radio" name="s" value="1"></td>
                    <td>Player</td>
                </tr>
                <tr>
                    <td><input type="radio" name="s" value="2"></td>
                    <td>Guild (Name)</td>
                </tr>
                <tr>
                    <td><input type="radio" name="s" value="3"></td>
                    <td>Guild (Guild Tag)</td>
                </tr>
                <tr>
                    <td>Text:</td>
                    <td colspan="2"><input type="text" name="xs" size="30" maxlength="30" value=""></td>
                </tr>
                <tr>
                    <td colspan="3"><input type="submit" value="Search" class="button3" name="search"></td>
                </tr>
            </table>
        </p>
    </form>
        </div></div>
<br />
<?if($functions->Search() == false) {?> 
    <div class="title_box"><div class="title_inner">
        Results </div></div>
    <div class="title2_box"><div class="title2_inner">
    <p>
                    <table width="50%">
            <tr>
                <td>Player</td>
                <td>Level</td>
                <td>Total honour</td>
            </tr>
            <tr><td class="f" colspan="2">No results</td></tr></table>  </p>
    </div></div>
    <?} else {?>
        <div class="title_box"><div class="title_inner">
        Results </div></div>
    <div class="title2_box"><div class="title2_inner">
    <p>
                    <table width="50%">
            <tr>
                <td>Player</td>
                <td>Level</td>
                <td>Total honour</td>
            </tr>
            <tr><td class="f" colspan="2"><?$functions->Search();?></td></tr></table>   </p>
    </div></div>
    <?}?>
</div>  

<script type='text/javascript'>var tickerArray = new Array();function doTicker(){
                                    n=new Date();
                                    if (tickerArray.length > 0)
                                    {
                                        for (i = 0; i < tickerArray.length; i++)
                                        {
                                            if (isNaN(document.getElementById(tickerArray[i]["id"])))
                                            {
                                                var e = document.getElementById(tickerArray[i]["id"]);
                                                s = tickerArray[i]["sek"];
                                                m = 0;
                                                h = 0;
                                                d = 0;
                                                if (s < 0)
                                                    e.innerHTML = "---";
                                                else
                                                {
                                                    var timeTXT = s + " s";
                                                    if (s > 59)
                                                    {
                                                        m = Math.ceil(s / 60);
                                                        s = s-m * 60;
                                                        timeTXT = m + " m";
                                                    }
                                                    if (m > 59)
                                                    {
                                                        h = Math.ceil(m / 60);
                                                        m = m - h * 60;
                                                        timeTXT = h + " h";
                                                    }
                                                    if (h > 24)
                                                    {
                                                        d = Math.ceil(h / 24);
                                                        h = h-d * 24;
                                                        timeTXT = d + " d";
                                                    }

                                                    e.innerHTML = timeTXT;
                                                    tickerArray[i]["sek"]--;
                                                }
                                            }
                                        }
                                    window.setTimeout("doTicker();",999);
                                }
                            }doTicker();</script>
</div>
4

2 回答 2

1

SELECT * FROM users where username like 'k%' 将返回用户名以 k ​​开头的所有用户记录

SELECT * FROM user where username LIKE '%k%'

将返回所有包含字符 k 的用户记录

http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like

于 2013-04-05T20:43:21.147 回答
0
  1. 使用这个简单的代码: http ://www.simonerodriguez.com/ajax-form-submit-example/

  2. 删除表单上的“on_submit”操作。

  3. 在文本框中,添加属性:onKeyDown="xmlhttpPost('response_ajax.php, 'MyForm', 'MyResult', ''); return false;"

  4. 第三个参数“MyResult”将是您在 php 文件中输出的任何内容,因此它将被放置在一个名为“MyResilt”的 div 中 div id = “MyResult”"> /div>

您的 php 文件可以输出如下内容: echo "$Result"

那会做你想做的事。

于 2013-04-05T20:45:39.280 回答