简体   繁体   English

搜索结果(显示更多结果)

[英]Search Results (Show more results)

I have a search box where users can search for other users in a few types of ways, firstname, lastname, username or email within a drop down. 我有一个搜索框,用户可以在其中通过几种方式搜索其他用户,名字,姓氏,用户名或电子邮件。 This drop down shows the top 8 results and then I show a link at the bottom saying find more results with the bit of text they may have inputted into the search. 此下拉列表显示了前8个结果,然后我在底部显示了一个链接,说找到更多结果,并可能输入了一些文本。

So for instance if I type in JOHN but only type 'JO' of his name this is the value $_GET['t'] should send through to the searchresults page. 因此,例如,如果我键入JOHN,但仅键入他的名字的“ JO”,则该值$ _GET ['t']应该发送到searchresults页面。 So I got as far as the link. 所以我知道了链接。 But I just don't know what the query should be 但是我只是不知道查询应该是什么

Show more results link 显示更多结果链接

<a href='include/searchresults.php?ref=".$_GET['t']."'>Show More Results for ".$_GET['t']."</a>

SEARCHRUSULTS.PHP SEARCHRUSULTS.PHP

    if(isset($_GET['t'])){
$_GET['t'] = str_replace(" ", "", $_GET['t']);
$_GET['t'] = str_replace("%", "", $_GET['t']);

$_GET['t'] = mysqli_real_escape_string($mysqli,$_GET['t']);

if(strlen($_GET['t'])>1){

$sql="SELECT * FROM users WHERE username LIKE '%".$_GET['t']."%' OR first LIKE '%".$_GET['t']."%' OR last LIKE '%".$_GET['t']."%' OR email LIKE '%".$_GET['t']."%' ORDER BY first ASC";
$query=mysqli_query($mysqli,$sql);
$count = mysqli_num_rows($query); 

    if($count<=0){
        echo "No results found";
    }else{
    echo "<table width='100%'>";
        while($user_data=mysqli_fetch_array($query)){}

Try something like this, using MATCH insted of LIKE is much faster. 尝试这样的事情,使用LIKE的MATCH会更快。

$keyword=mysql_real_escape_string($_GET['t']);
$rowsperpage=8;
$sql="SELECT * FROM users WHERE MATCH (first, last, email) AGAINST ('+$keyword*' IN BOOLEAN MODE)   ORDER by first LIMIT $rowsperpage"; 
$query=mysqli_query($mysqli,$sql);
$count = mysqli_num_rows($query); 

and set $rowsperpage as you like. 并根据需要设置$rowsperpage

For more result page do something like this 对于更多结果页面,请执行以下操作

$rowsperpage=mysql_real_escape_string($_GET['rpp']);
<a href='include/searchresults.php?t=$keyword&rpp=$rowsperpage'>Show More Results for "$keyword"</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM