mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/10737] Code fixes in AJAX search feature
PHPBB3-10737
This commit is contained in:
parent
bc67377400
commit
b5ee81dae6
3 changed files with 32 additions and 33 deletions
|
@ -982,21 +982,24 @@ switch ($mode)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'livesearch':
|
case 'livesearch':
|
||||||
$q=request_var('q', '', true);
|
$username_chars = $request->variable('q', '', true);
|
||||||
$hint="";
|
$hint = "";
|
||||||
$sql = "SELECT username, user_id
|
|
||||||
FROM " . USERS_TABLE . " u
|
$sql = 'SELECT username, user_id
|
||||||
WHERE username LIKE '".$q."%' AND u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")";
|
FROM ' . USERS_TABLE . '
|
||||||
$result = $db->sql_query($sql);
|
WHERE ' . $db->sql_in_set('user_type', array(USER_NORMAL, USER_FOUNDER)) . '
|
||||||
$i=1;
|
AND username ' . $db->sql_like_expression($username_chars . $db->any_char);
|
||||||
while ($i<=10 && $row = $db->sql_fetchrow($result))
|
$result = $db->sql_query_limit($sql, 10);
|
||||||
|
|
||||||
|
$i = 1;
|
||||||
|
while ($row = $db->sql_fetchrow($result))
|
||||||
{
|
{
|
||||||
$j=($i%2)+1;
|
$j = ($i%2)+1;
|
||||||
$hint.="<tr class='bg".$j." row".$j."'><td><a href='" .
|
$hint.= "<tr class='bg".$j." row".$j."'><td><a href='" .
|
||||||
$phpbb_root_path."memberlist.$phpEx". "?mode=viewprofile&u=" . $row['user_id'] .
|
$phpbb_root_path."memberlist.$phpEx". "?mode=viewprofile&u=" . $row['user_id'] .
|
||||||
"' target='_blank'>" .
|
"' target='_blank'>" .
|
||||||
$row['username'] . "</a></td></tr>";
|
$row['username'] . "</a></td></tr>";
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
echo $hint;
|
echo $hint;
|
||||||
exit();
|
exit();
|
||||||
|
|
|
@ -1,23 +1,21 @@
|
||||||
<script>
|
<script>
|
||||||
function showHint(str)
|
function showHint(str) {
|
||||||
{
|
if (str.length<3) {
|
||||||
if (str.length<3)
|
|
||||||
{
|
|
||||||
document.getElementById("livesearch").innerHTML="";
|
document.getElementById("livesearch").innerHTML="";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url:'{S_LIVE_SEARCH_ACTION}'+"&q="+str,
|
url:'{S_LIVE_SEARCH_ACTION}'+"&q="+str,
|
||||||
success:function(result){
|
success:function(result) {
|
||||||
$("#livesearch").html(result);
|
$("#livesearch").html(result);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function clearSearch() {
|
||||||
function clearSearch()
|
setTimeout(function () {
|
||||||
{
|
document.getElementById("livesearch").innerHTML="";
|
||||||
document.getElementById("livesearch").innerHTML="";
|
}, 500);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -32,7 +30,7 @@
|
||||||
<fieldset class="fields1 column1">
|
<fieldset class="fields1 column1">
|
||||||
<dl>
|
<dl>
|
||||||
<dt><label for="username">{L_USERNAME}{L_COLON}</label></dt>
|
<dt><label for="username">{L_USERNAME}{L_COLON}</label></dt>
|
||||||
<dd><input type="text" name="username" id="username" value="{USERNAME}" class="inputbox" onkeyup="showHint(this.value)" onblur="clearSearch()" /> <table class="table1" id="livesearch"></table> </dd>
|
<dd><input type="text" name="username" id="username" value="{USERNAME}" class="inputbox" autocomplete="off" onkeyup="showHint(this.value)" onblur="clearSearch()" /> <table class="table1" id="livesearch"></table> </dd>
|
||||||
</dl>
|
</dl>
|
||||||
<!-- IF S_EMAIL_SEARCH_ALLOWED -->
|
<!-- IF S_EMAIL_SEARCH_ALLOWED -->
|
||||||
<dl>
|
<dl>
|
||||||
|
|
|
@ -65,25 +65,23 @@
|
||||||
<!-- ENDIF -->
|
<!-- ENDIF -->
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function showHint(str)
|
function showHint(str) {
|
||||||
{
|
if (str.length<3) {
|
||||||
if (str.length<3)
|
|
||||||
{
|
|
||||||
document.getElementById("livesearch").innerHTML="";
|
document.getElementById("livesearch").innerHTML="";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url:'{S_LIVE_SEARCH_ACTION}'+"&q="+str,
|
url:'{S_LIVE_SEARCH_ACTION}'+"&q="+str,
|
||||||
success:function(result){
|
success:function(result) {
|
||||||
$("#livesearch").html(result);
|
$("#livesearch").html(result);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function clearSearch() {
|
||||||
function clearSearch()
|
setTimeout(function () {
|
||||||
{
|
document.getElementById("livesearch").innerHTML="";
|
||||||
document.getElementById("livesearch").innerHTML="";
|
}, 500);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -98,7 +96,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="row1"><b class="genmed">{L_USERNAME}{L_COLON}</b></td>
|
<td class="row1"><b class="genmed">{L_USERNAME}{L_COLON}</b></td>
|
||||||
<td class="row2"><input class="post" type="text" name="username" value="{USERNAME}" onkeyup="showHint(this.value)" onblur="clearSearch()" /> <table class="tablebg" id="livesearch"></table> </td>
|
<td class="row2"><input class="post" type="text" name="username" value="{USERNAME}" autocomplete="off" onkeyup="showHint(this.value)" onblur="clearSearch()" /> <table class="tablebg" id="livesearch"></table> </td>
|
||||||
<!-- IF S_EMAIL_SEARCH_ALLOWED -->
|
<!-- IF S_EMAIL_SEARCH_ALLOWED -->
|
||||||
<td class="row1"><b class="genmed">{L_EMAIL}{L_COLON}</b></td>
|
<td class="row1"><b class="genmed">{L_EMAIL}{L_COLON}</b></td>
|
||||||
<td class="row2"><input class="post" type="email" name="email" value="{EMAIL}" /></td>
|
<td class="row2"><input class="post" type="email" name="email" value="{EMAIL}" /></td>
|
||||||
|
|
Loading…
Add table
Reference in a new issue