This topic is locked

generating random numbers

6/22/2005 6:59:03 PM
PHPRunner General questions
S
suzy author

Hi, Sergey -

I need to generate random number on my Parts table's add page. I put this code within the <?php & ?> codes on the parts_add page.

//produce random numbers

srand((double)microtime()*1000000);

//number between 300000000 and 399999999

$random_number1 = rand(300000000,399999999);


and then, under formatting, under 'edit as', I have added this expression under default value of this text field

<?php echo ("$random_number1"); ?>


Seems like that ought to work, doesn't it?
I cannot see all the examples of expressions on that default value page, so don't know for sure if my expression is correct. Apparently not.
I get this error message:

Parse error: parse error, unexpected T_ECHO in /home/webs/americantrans/CAT2/include/PARTS_functions.php on line 537
Is there an easier way to generate a random number on the add page, such as that for new parts?
Thanks.

admin 6/27/2005

Suzy,
default value should be a valid PHP expression.
First set the following default value for your field in PHPRunner:

rand(300000000,399999999)


Then build the pages and insert the following in the beginning of ..._add.php file

//produce random numbers

srand((double)microtime()*1000000);