简体   繁体   English

PHP-MYSQL未在搜索查询中选择

[英]PHP - MYSQL not selecting in search query

I am building a mini test php thing. 我正在建立一个迷你测试PHP的东西。 And I need to be able to search the results. 而且我需要能够搜索结果。 This works great. 这非常有效。 But I cannot seem to make a paging system around this. 但是我似乎无法为此建立一个分页系统。 I sort of know how to make a paging system, however, I cannot seem to do this because the mysql query is not only searching the table records which idedu_details is equal to $edu_details: 我有点知道如何制作分页系统,但是,我似乎无法做到这一点,因为mysql查询不仅在搜索idedu_details等于$ edu_details的表记录:

$search_result = mysql_query("SELECT * FROM test WHERE idedu_details='".$edu_details."' AND first_name LIKE '%".$search."%' OR surname LIKE '%".$search."%'");

here is my complete code: 这是我的完整代码:

$search_result = mysql_query("SELECT * FROM test WHERE idedu_details='".$edu_details."' AND first_name LIKE '%".$search."%' OR surname LIKE '%".$search."%'");

    while($row_search = mysql_fetch_array($search_result)){


                $idedu_detail_check = mysql_query("SELECT * FROM test WHERE idtest='".$row_search['idtest']."'") or die(mysql_error());
                $row_idedu_check = mysql_fetch_array($idedu_detail_check);

                if($row_idedu_check['idedu_details'] == $edu_details){
                $testid = $row_search['idtest'];
                $firstName = $row_search['first_name'];
                $surname = $row_search['surname'];
                $dob = $row_search['dob'];
                $date = $row_search['date'];
                $status = $row_search['status'];
                $link = "report.php?id=$testid";
                $button = '<button onClick="parent.location='. "'".$link."'".'">Analyse</button>';

                echo "<tr>
                    <td width='100'>$firstName</td>
                    <td width='100'>$surname</td>
                    <td width='100'>$dob</td>
                    <td width='100'>$date</td>
                    <td width='100'>$status</td>
                    <td width='100'>$button</td>

                    </tr>";
                }//end if idedu_detail check

            }//end while

        }//end else search != null

How can I make a paging system around this? 我怎样才能围绕这建立一个寻呼系统?

EDIT: I know how to make a general paging system. 编辑:我知道如何使通用分页系统。 However, checking the ided_details = $edu_details and building a paging system around this is causing an issue. 但是,检查ided_details = $ edu_details并围绕此构建一个分页系统会引起问题。

First you would need to set a limit to the results that are being retrieved. 首先,您需要为要检索的结果设置一个限制。 Secondly, you have done nothing to paginate the page, try something and let us know what you can't do. 其次,您什么也没做,无法对页面进行分页,尝试某些操作并让我们知道您不能执行的操作。 :) :)

I think you're saying that your SQL query is pulling where idedu_details!=$edu_details. 我认为您是说您的SQL查询正在将idedu_details!= $ edu_details拉到哪里。 Try putting in parentheses around the 2 ORs: 尝试在两个OR之间加上括号:

$search_result = mysql_query("SELECT * FROM test WHERE idedu_details='".$edu_details."' AND (first_name LIKE '%".$search."%' OR surname LIKE '%".$search."%')");

I think you forgot to add parenthesis in WHERE clause: 我认为您忘记在WHERE子句中添加括号:

$search_result = mysql_query("
    SELECT * 
    FROM test 
    WHERE 
        idedu_details='".$edu_details."' AND 
        ( first_name LIKE '%".$search."%' OR surname LIKE '%".$search."%' )
");

Keep in mind that AND always takes precedence over OR . 请记住, AND始终优先于OR

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

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