samp / mysql
#1

How can I generate a random 6 digits number without digit 0 as the first digit as a phone number?

ex: 244132, 131131, 121412

I want them to be saved in MYSQL when someone types /buyphone (i can do this)

help me just with the generator number, the rest of script I can do it alone, I don't know how to do it via pawn

And I don't know how to check it in MYSQL if already exists that number, to give another random number.
Reply
#2

this may help
Код:
 mysql_format(connectionID, queryBuffer, sizeof(queryBuffer), "UPDATE users SET phone = %i WHERE uid = %i", PlayerInfo[playerid][pPhone], PlayerInfo[playerid][pID]);
mysql_tquery(connectionID, queryBuffer);
Reply
#3

PHP код:
createphone(){
       new 
number[6];
       for(new 
i=0j=6i<ji++){
              
random(9+1); // this will give you a number from 1 to 9 it can be used like this
              
number[i] = random(9+1); // This might work or might not, haven't tested it yet
       
}
       return 
number;

It's a theory, don't know if it works

do what TitoRayne showed and it will save on MySQL
Reply
#4

Are you cool now bruv?
Reply
#5

No, I don't know how to do the stock (question edited)
Reply
#6

Код:
new phonenumber[6];
phonenumber[0] = rand(8)+1; // sets the first number from 1 to 9
for(new i=i; i<sizeof(phonenumber);i++)
{
    phonenumber[i]=rand(9); // sets the rest of the numbers from 0 to 9
}
And I'm not sure about the mysql part as I'm not that good with mysql myself but you can try:
PHP код:
new query[256]
// select all the phone numbers that match the phone number you want
mysql_format(yourDatabasequerysizeof query"SELECT * FROM `yourTable` WHERE `phonenumber` = '%i' LIMIT1"thePhoneNumberYouGotFromTheCommand )
mysql_query(yourDatabasequerycallbackFunctionparameterTypeparameter );
forward yourCallbackFunction(parameter);
public 
yourCallbackFunction(parameter)
{
   if(
cache_num_rows() > 0// if the phone number is found in the database
   
{
       
// do something
   
}

And of course you have to replace the name of yourDatabase, yourTable, phonenumber and everything else to match yours.
Reply
#7

Hi, I did this way

PHP код:
CMD:number(playeridparams[])
{
    if(
pInfo[playerid][Telefon] == 0)
    {
        new 
string[220], number randomEx(1000,99999999);
        
pInfo[playerid][Telefon] = number;
        
format(stringsizeof(string), "Your phonenumber is: %i",pInfo[playerid][Telefon]);
        
SendClientMessage(playerid,-1,string);
        
SaveStats(playerid);
    }
    else {
        
SendClientMessage(playerid,-1,""chat" You already have an phone number !");
    }
    return 
1;

Thanks anyway
Reply
#8

Quote:
Originally Posted by Zeus666
Посмотреть сообщение
Hi, I did this way

PHP код:
CMD:number(playeridparams[])
{
    if(
pInfo[playerid][Telefon] == 0)
    {
        new 
string[220], number randomEx(1000,99999999);
        
pInfo[playerid][Telefon] = number;
        
format(stringsizeof(string), "Your phonenumber is: %i",pInfo[playerid][Telefon]);
        
SendClientMessage(playerid,-1,string);
        
SaveStats(playerid);
    }
    else {
        
SendClientMessage(playerid,-1,""chat" You already have an phone number !");
    }
    return 
1;

Thanks anyway
You should do : "randomEx(111111,999999);" It will give you a random number without a zero and in range of 6 digits.
Reply
#9

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
You should do : "randomEx(111111,999999);" It will give you a random number without a zero and in range of 6 digits.
Well, changed my mind a little bit there. :d
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)