SA-MP Forums Archive
MySQL and randoms car numbers. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL and randoms car numbers. (/showthread.php?tid=470517)



MySQL and randoms car numbers. - MrMou6 - 18.10.2013

Hello, I made my function:
Код:
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)
	{	
		// what i should write here?
        }
	else
	{
		mysql_free_result();
		return string;
	}
}
That should make random numbers for my car.
But I want that code dont creat the same numbers.
And i dont know what I should write after:
Код:
if(mysql_num_rows() > 0)
Can someone help me?

P.S. sorry for my bad english


Re: MySQL and randoms car numbers. - MrMou6 - 19.10.2013

Can someone help?


Re: MySQL and randoms car numbers. - RajatPawar - 19.10.2013

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.


Re: MySQL and randoms car numbers. - MrMou6 - 19.10.2013

Thanks for help