This topic is locked
[SOLVED]

 Random number

5/27/2010 10:16:59 AM
PHPRunner General questions
M
munkeh author

Hello,
Does anyone have a tip to use a random number generator in phprunner after a new record is added? (put a random number of 6 letters or numbers in to a record before the new record is added)

The random number generator has to be 6 numbers or letters (doesnt matter really)
Thanks in advance,

Regards,

A
ann 5/28/2010

Hi,
you can use Before record added event on the Events tab.

Here is a sample code:

$values["FieldName"]=mt_rand(100000,999999);



where FieldName is actual field name.

For more information: http://www.w3schools.com/php/func_math_mt_rand.asp

M
munkeh author 5/31/2010



Hi,
you can use Before record added event on the Events tab.

Here is a sample code:

$values["FieldName"]=mt_rand(100000,999999);



where FieldName is actual field name.

For more information: http://www.w3schools.com/php/func_math_mt_rand.asp


Hello, thanks alot for that.

One question : with this generator, is it possible that 2 records have the same number? I guess so. I forgot to add the number can only be used once.

A
ann 6/1/2010

Hi,
use predefined event Check if specific record exists (Add action button on the Events tab) just after.

M
munkeh author 6/24/2010



Hi,
use predefined event Check if specific record exists (Add action button on the Events tab) just after.


$values["code"]=mt_rand(100000,999999);

//** Check if specific record exists ****

global $conn;

$strSQLExists = "select * from AnyTable where SomeColumn='SomeValue'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

// if record exists do something

}

else

{

// if dont exist do something else

}
What is needed in the 'SomeValue' value then since its a random number?

thanks,

A
ann 6/25/2010

Hi,
random value is defined before in your code. Just repalce SomeValue with $values["code"] in your event:

$strSQLExists = "select * from AnyTable where SomeColumn=".$values["code"];



where AnyTable is your actual table name, SomeColumn is actual field name.