[FX.php List] User exists - offer other names
Joel Shapiro
jsfmp at earthlink.net
Wed Aug 22 12:00:12 MDT 2007
Hi William
I'm assuming the usernames are fields and not actual FM accts, correct?
Another thought, riffing somewhat off of Steve's:
Do a find for the requested username, but don't search for an exact
match ( '=='.$_POST['username']), just do a regular find (without the
'=='). That way, in one hit to the DB you'll get back
willsmith
wills
willshapiro
willshakespeare
wills101
when the user enters 'wills'. (those 5 are already in the DB)
Then you can loop through the returned results to see if there any
are exact matches. If there is, then create 10 other unique
suggestions and loop back through the same results, dropping
suggestions if they match anything in the returned results, and
stopping once you've got 5 unique suggestions. (alternatively,
create the suggestions one at a time and loop through each time, but
you'd need to make sure that you don't create a suggestion #4 that
you already created as #2)
One thing that *might* require some additional thought: If you allow
multiple-word usernames, then 'wills' would also find 'free wills' --
but I can't at the moment see that this would be a problem.
HTH,
-Joel
On Aug 22, 2007, at 9:55 AM, Steve Winter wrote:
> Hi William,
>
> An interesting challenge... a few options to consider... once you
> know the
> name isn't available you could...
>
> 1. download every existing username into a PHP array, generate
> suggestions,
> test to see if they are in that array, if not, add them to the list
> until
> you have 5. pro - only one call to the db, con - once you have a
> lot of
> users, it's a BIG array and may take a while to process
>
> 2. generate a suggestion, perform a lookup in the db for that
> suggestion, if
> it's not found add it to the list, and repeat till you have five
> options on
> the list pro - doesn't matter how big the db gets, con - requires 6
> hits to
> the db
>
> 3. a modification of 1, define that all of your suggestions are
> going to use
> the exact username that the person requested, then append other
> characters
> to it, so create an array of all usernames which have those
> characters as
> the beginning of them, then generate options and test against that
> array...
> pro - doesn't matter how big the db gets, only requires 2 db calls,
> con -
> none that spring to mind
>
> This seems the best way to go to me so I'll give an example;
>
> Current usernames in database;
> .
> .
> .
> steveSmith
> steveSmithson
> steveWinter
> steveWinterNZ
> steveWinter1970
> steveYeates
> steveYeateson
> .
> .
> .
>
> User requests steveWinter
>
> It already exists, so your second request to the db is 'find all
> usernames
> beginning with steveWinter and load them into an array called
> $currentNames'
>
> Generate a suggested username, depending on what other data you
> asked them
> for you could use options like appending their country code, their
> year of
> birth, the place they live etc... or if you don't have any other
> personal
> data, you could just use a sequential number, the current year, the
> current
> day, whatever...
>
> Once you've made up a username test it against the array of current
> ones, if
> it's not in there add it to a new array of suggestions, until that
> array has
> 5 items...
>
> Hope this helps... if you want to follow this through and need help
> with
> coding this get back to us...
>
> Cheers
> Steve
>
>
> -----Original Message-----
> From: fx.php_list-bounces at mail.iviking.org
> [mailto:fx.php_list-bounces at mail.iviking.org] On Behalf Of William
> Downs
> Sent: Wednesday, 22 August 2007 10:07 a.m.
> To: FX.php Discussion List
> Subject: [FX.php List] User exists - offer other names
>
> Hi guys,
>
> I'm looking for something here and have no idea where to start !
>
> I am building a DB where a user can enter themselves - contact data
> and user name.
> I am looking for a way to say "This user name is already taken. Please
> enter another name"
>
> This I can do - what I CANNOT do is offer them a selection of names (5
> possibilities) that also do not exist !
>
> Example entered:
> User name = wills
> Returns:
> This user name is already taken. Please enter another name. Possible
> examples are
> wills100
> wills200
> wills300
> wills101
> wills202
> Or enter an entirely new name.
>
> Of course, none of the above 5 names exist either.
>
> Any ideas ?
>
> William
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
>
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.484 / Virus Database: 269.12.1/965 - Release Date:
> 21/08/2007
> 4:02 p.m.
>
>
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.5.484 / Virus Database: 269.12.1/965 - Release Date:
> 21/08/2007
> 4:02 p.m.
>
>
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
More information about the FX.php_List
mailing list