I am building a mini test php thing. 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:
我正在构建一个迷你测试php的东西。我需要能够搜索结果。这很好用。但我似乎无法围绕这个制作寻呼系统。我有点知道如何建立一个分页系统,但是,我似乎无法做到这一点,因为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并围绕此构建分页系统会导致问题。
3 个解决方案
#1
1
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。
#2
1
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. :)
首先,您需要为要检索的结果设置限制。其次,你没有做任何事情来分页页面,尝试一些东西,让我们知道你不能做什么。 :)
#3
1
I think you're saying that your SQL query is pulling where idedu_details!=$edu_details. Try putting in parentheses around the 2 ORs:
我想你是说你的SQL查询正在拉动idedu_details!= $ edu_details。尝试在2个OR周围加上括号:
$search_result = mysql_query("SELECT * FROM test WHERE idedu_details='".$edu_details."' AND (first_name LIKE '%".$search."%' OR surname LIKE '%".$search."%')");
#1
1
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。
#2
1
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. :)
首先,您需要为要检索的结果设置限制。其次,你没有做任何事情来分页页面,尝试一些东西,让我们知道你不能做什么。 :)
#3
1
I think you're saying that your SQL query is pulling where idedu_details!=$edu_details. Try putting in parentheses around the 2 ORs:
我想你是说你的SQL查询正在拉动idedu_details!= $ edu_details。尝试在2个OR周围加上括号:
$search_result = mysql_query("SELECT * FROM test WHERE idedu_details='".$edu_details."' AND (first_name LIKE '%".$search."%' OR surname LIKE '%".$search."%')");