PDA

View Full Version : Memberlist Search


Boofo
08-21-2002, 01:08 AM
Can anyone please tell me how to make the following code to a partial serach for a member instead of having to have the full member name first?

if ($action=="quickfind") {
$usernamecheckq = $DB_site->query("SELECT userid FROM user WHERE username='".addslashes(htmlspecialchars($membername))."'");
$usernamecheck = mysql_fetch_array($usernamecheckq);
if (!$usernamecheck[userid]) {
eval("standarderror(\"".gettemplate("error_invalidusername")."\");");
exit; }
$goto="member.php?s=$session[sessionhash]&action=getinfo&userid=$usernamecheck[userid]";
eval("standardredirect(\"".gettemplate("redirect_memberfound")."\",\"$goto\");");
}

Xenon
08-21-2002, 03:51 PM
instead of username='".addslashes($membername)."'
use username LIKE '%".addslashes($membername)."%'

Boofo
08-21-2002, 06:18 PM
Ok, that worked, thank you. Now, how can I pull out the full username from the search and display it in the "redirect_memberfound" template. If I use "$membername" like it is now, it pulls out what was in the search string (like boofos ba) instead of the full username. Also, is there a way to have it bring up a listing of just the names found in the search so the user can pick from them?

Originally posted by Xenon
instead of username='".addslashes($membername)."'
use username LIKE '%".addslashes($membername)."%'

Xenon
08-21-2002, 08:25 PM
you have to construct a while loop to get all usernames...

to get the correct username instead of $membername use $usernamecheck[username]

Boofo
08-21-2002, 09:07 PM
Ok, but will that do an excessive amount of queries then?

I tried using $usernamecheck[username] and all I get is a blank spot where the name should be. :)

Originally posted by Xenon
you have to construct a while loop to get all usernames...

to get the correct username instead of $membername use $usernamecheck[username]

Xenon
08-22-2002, 10:35 AM
no, no great ammount of queries, just one query and then just fetcharrays ;)

oh sorry, you must include ,username in the query: SELECT userid,username FROM...

Boofo
08-22-2002, 06:47 PM
Thanks, Stefan, now it brings up the username ok.

How do I get it to bring up the user alphabetically instead of going by the userid? Right now a user with a Marj in the name comes up before an Marc when I type Mar. It is going by when they joined right now. :)

Originally posted by Xenon
no, no great ammount of queries, just one query and then just fetcharrays ;)

oh sorry, you must include ,username in the query: SELECT userid,username FROM...

Xenon
08-22-2002, 06:56 PM
add a "ORDER BY username" into the query

Boofo
08-22-2002, 07:02 PM
I take it from my DB error, I put it in the wrong place? :)

$usernamecheckq = $DB_site->query("SELECT userid,username FROM user ORDER BY username WHERE username LIKE '%".addslashes(htmlspecialchars($membername))."%'");

Originally posted by Xenon
add a "ORDER BY username" into the query

Xenon
08-22-2002, 07:15 PM
SELECT userid,username FROM user WHERE username LIKE '%".addslashes(htmlspecialchars($membername))."%' ORDER BY username
shoud be right ;)

Boofo
08-22-2002, 07:20 PM
I'm getting this error now. :)

Parse error: parse error, unexpected T_STRING in /home/boofo/public_html/forum/memberlist.php on line 320

Xenon
08-22-2002, 07:23 PM
try now ;)

Boofo
08-22-2002, 07:27 PM
Still giving me errors. Here is what I have for that whole line now. What did I screw up? :)

$usernamecheckq = $DB_site->query("SELECT userid,username FROM user WHERE username LIKE '%".addslashes(htmlspecialchars($membername))."%' ORDER BY username);

Xenon
08-22-2002, 07:45 PM
add a " before the final ) ;)

Boofo
08-22-2002, 07:49 PM
Just shoot me. :) How in the heck could I miss something so obvious? I figured it out at the exact same time my Outlook pulled for mail and your message here showed up. This calls for a big DOOHHH!!!!! Thanks, Stefan. You would think I would learn, huh? :)

Originally posted by Xenon
add a " before the final ) ;)