我遇到的问题是,如果提交了该搜索表单,则不返回任何内容,但如果我只是正常刷新页面而没有提交,则可以正常工作并返回所有结果。正如你在下面看到的那样它设置了$ subleaguesearch和$ countrysearch变量,如果表单尚未提交并且工作正常,它就在提交时没有提交,而我似乎无法找到原因。任何帮助都会很棒!感谢。
p.s我没有收到任何错误消息,它根本没有返回任何内容。并且我在表单提交后将变量回显到屏幕,并且它们以正确的值回显,因此我知道变量设置正常!。
<form action="" method="post" autocomplete="off">
<table id="searchsubleaguetable" width="670px" align="left" cellpadding="1" cellspacing="0">
<tr colspan="2">
<th colspan="2" align="left"><label>SEARCH SUBLEAGUES</th>
</tr>
<tr>
<td align="right"><label>COUNTRY </td>
<td align="left"><SELECT NAME="country" style="font-size:12px; padding:4px;"><OPTION VALUE="0">All Countries<?php echo $options;?></option></SELECT></label></td>
</tr>
<tr>
<td align="right"><label>SEARCH </td>
<td align="left"><input class="searchinputs" type="text" name="subleaguesearch" size="40" value=""></label></td>
</tr>
<tr width="100%" height="20px" colspan="2">
<td align="right"><label></td>
<td align="left"><input class="searchbutton" type="submit" value="Search" name="searchsubnow"></label></td>
</tr>
</table>
</form>
if (isset($_POST['searchsubnow'])){
$subleaguesearch = mysql_real_escape_string($_POST['country']);
$countrysearch = mysql_real_escape_string($_POST['subleaguesearch']);
if($countrysearch == 0){
$countrysearch = "%%";
}
}else{
$subleaguesearch = "";
$countrysearch = "%%";
}
$rowsPerPage = 15;
$pageNum = 1;
if(isset($_GET['page'])){
$chosenpage = mysql_real_escape_string($_GET['page']);
$pageNum = $chosenpage;
}
$offset = ($pageNum - 1) * $rowsPerPage;
$result = mysql_query(" SELECT s.league_id, s.leaguename, s.private, s.date, u.flag, u.firstname, u.country,
COALESCE(SUM(r.total_points),0) as totalpoints,
count(m.member_id) participants
from sub_leagues s
Left Join members_leagues m
On m.league_id = s.league_id
Left Join member_results r
On r.member_id = m.member_id
join members u
on s.admin = u.member_id
WHERE u.country LIKE '$countrysearch'
AND s.leaguename LIKE '$subleaguesearch%'
Group By s.league_id
Order By r.total_points DESC, participants DESC, s.date ASC " . " LIMIT $offset, $rowsPerPage")
or die ("<br/> Error - could not display league");
答案 0 :(得分:1)
想象你的问题在于这段代码:
$subleaguesearch = mysql_real_escape_string($_POST['country']);
$countrysearch = mysql_real_escape_string($_POST['subleaguesearch']);
if($countrysearch == 0){
$countrysearch = "%%";
}
首先,您应该检查并确保$ _POST ['country']和$ _POST ['subleaguesearch']包含您认为它们包含的内容。如果他们不这样做,那么您最有可能错误地将表单中的字段命名为错误。
其次,您似乎已将错误的帖子字段分配给错误的搜索变量。注意$ subleaguessearch = $ _POST ['country']而不是等于$ _POST ['subleaguesearch']。与$ countrysearch相同。所以它应该是这样的:
$subleaguesearch = mysql_real_escape_string($_POST['subleaguesearch ']);
$countrysearch = mysql_real_escape_string($_POST['country']);