Jiraiya Posted April 7, 2009 Share Posted April 7, 2009 i have a script that generates a random number <?php echo (rand(1,10)); ?> my question is how do i set a mysql variable to equal that random number all in one script? Link to comment https://forums.phpfreaks.com/topic/153007-php-random-number/ Share on other sites More sharing options...
Maq Posted April 7, 2009 Share Posted April 7, 2009 Do you mean something like: $var = rand(1, 10); $sql = "SELECT * FROM table WHERE id = '$var'"; mysql_query($sql) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/153007-php-random-number/#findComment-803617 Share on other sites More sharing options...
Jiraiya Posted April 7, 2009 Author Share Posted April 7, 2009 yea kinda i have the variable set to "0" on default so i guess it would be an update mabey? Link to comment https://forums.phpfreaks.com/topic/153007-php-random-number/#findComment-803619 Share on other sites More sharing options...
Maq Posted April 7, 2009 Share Posted April 7, 2009 yea kinda i have the variable set to "0" on default so i guess it would be an update mabey? Maybe... I have no clue what you're trying to accomplish here. Link to comment https://forums.phpfreaks.com/topic/153007-php-random-number/#findComment-803622 Share on other sites More sharing options...
Jiraiya Posted April 7, 2009 Author Share Posted April 7, 2009 here is the code it displays a random number but doesn't update the variable $username = $_COOKIE['ID_my_site']; $sql = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error()); echo (rand(1,10)); $var = rand(1, 10); $sql = "SELECT * FROM users WHERE number = '$var'"; mysql_query($sql) or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/153007-php-random-number/#findComment-803623 Share on other sites More sharing options...
phil88 Posted April 7, 2009 Share Posted April 7, 2009 I still don't understand what you're trying to do... what are you trying to update? and with what? Link to comment https://forums.phpfreaks.com/topic/153007-php-random-number/#findComment-803628 Share on other sites More sharing options...
Jiraiya Posted April 7, 2009 Author Share Posted April 7, 2009 im trying to set the random number that is generated to be set as the value of variable "number" Link to comment https://forums.phpfreaks.com/topic/153007-php-random-number/#findComment-803630 Share on other sites More sharing options...
premiso Posted April 7, 2009 Share Posted April 7, 2009 $sql = "UPDATE users SET number = '$var' WHERE username = '$username'"; You said the answer yourself.... Link to comment https://forums.phpfreaks.com/topic/153007-php-random-number/#findComment-803632 Share on other sites More sharing options...
Maq Posted April 7, 2009 Share Posted April 7, 2009 Just a guess ??? $username = $_COOKIE['ID_my_site']; $var = rand(1, 10); $sql = "UPDATE users SET number = '$var' WHERE username = '$username'"; echo "QUERY=> " . $sql; mysql_query($sql) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/153007-php-random-number/#findComment-803634 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.