Check if phone number exist
#1

Hello,

Is this idea good to check if a phone number exist already?

Код:
new randphone = 0, number = 0, ok = 0, query[64];
					format(query, sizeof(query), "SELECT Phone FROM players WHERE Phone > 0");
					new Cache: numbers = mysql_query(SQL, query);
					do
					{
						ok = 1;
						randphone = 10000 + random(89999);
						if(cache_get_row_count() > 0)
						{
							for(new i, j = cache_get_row_count(); i != j; i++)
							{
								number = cache_get_field_content_int(i, "Phone");
								if(number == randphone)
								{
									ok = 0;
								}
							}
						}
					}
					while(ok == 0);
					cache_delete(numbers);
I don't want to check database everytime, so I made it with cache. I don't know if this code is good... And I want to ask if there is a function better than this one... I don't know if is a good idea to make a loop in another one and I don't want to make an infinite loop than can result in a server freeze.
Reply
#2

Why don't you let the players choose their phone number? It'd be a lot easier to check if it already exists or not and they'll remember it as they were the ones who picked it.

Just sayin'
Reply
#3

Does it need to be completely random, though? Because you could just use the player's unique SQL id in the number. Like the first two digits are random(100) and the last four digits are the player's unique id, padded with zeros if it's less than 1000 (%04d). This method may make it slightly obvious what's going one because the first players will have xx0001, xx0002, xx0003, etc. But it should appear more random once registered player count reaches above 100.
Reply
#4

Quote:
Originally Posted by Troydere
Посмотреть сообщение
Why don't you let the players choose their phone number? It'd be a lot easier to check if it already exists or not and they'll remember it as they were the ones who picked it.

Just sayin'
It's more realistic to give them random phone numbers.

Quote:
Originally Posted by Vince
Посмотреть сообщение
Does it need to be completely random, though? Because you could just use the player's unique SQL id in the number. Like the first two digits are random(100) and the last four digits are the player's unique id, padded with zeros if it's less than 1000 (%04d). This method may make it slightly obvious what's going one because the first players will have xx0001, xx0002, xx0003, etc. But it should appear more random once registered player count reaches above 100.
Yeah, I want it random. I have already 10k players registered so I think this will not work fine...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)