Page 1 of 1

insertign a random number

Posted: Mon Jun 05, 2006 10:17 am
by hame22
Hi I need some help in inserting a random number in a query

I need a number to be generated between 1 - 20 and then inserted into my database via a query.

Form should be something like this

Code: Select all

$result = mysql_query("Insert into activities set downloads = *random number*");
is there a way to do this either via mysql or php?

thanks in advance

Posted: Mon Jun 05, 2006 10:23 am
by twigletmac
In PHP you can use rand(). MySQL also has a RAND() function which works slightly differently.

Mac

Posted: Mon Jun 05, 2006 10:25 am
by bdlang
PHP Manual: rand()
PHP Manual: mt_rand()

You might find this recent (yesterday) topic useful:
viewtopic.php?t=49523

Posted: Mon Jun 05, 2006 11:26 am
by ok

Code: Select all

mt_rand(1, 20);
!!!!!