MySQL and randoms car numbers.
#3

Just use recursion
pawn Код:
stock RandomCarNumbers()
{
    new string[64], query[128];
    format(string,sizeof(string),"{000000}%c%c%c-%i%i%i",(65+random(26)),(65+random(26)),(65+random(26)),1+random(9),random(10),random(10));
    MySQLCheck();
    format(query, sizeof(query), "SELECT * FROM 'cars' WHERE numeriai = %s", string);
    mysql_query(query);
    mysql_store_result();
    if(mysql_num_rows() > 0)
    return
        RandomCarNumbers();
    else
    {
        mysql_free_result();
        return string;
    }
}
It will keep calling itself until you have a car number that's unique.
Reply


Messages In This Thread
MySQL and randoms car numbers. - by MrMou6 - 18.10.2013, 15:12
Re: MySQL and randoms car numbers. - by MrMou6 - 19.10.2013, 08:04
Re: MySQL and randoms car numbers. - by RajatPawar - 19.10.2013, 08:07
Re: MySQL and randoms car numbers. - by MrMou6 - 19.10.2013, 08:50

Forum Jump:


Users browsing this thread: 1 Guest(s)