twilitegxa Posted September 22, 2008 Share Posted September 22, 2008 I found this code online, but I don't understand what this part means. It says: // to specify the number of dice rolls rather than allowing the user // to choose, change the second block to $i <= [number of rolls] I don't understand what the second block means. What do I change? Can anyone help me out here? The cod is below: <?php session_start() ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Let's roll some dice!</title> </head> <body> <h2><i>Let's roll some dice!</i></h2> <br /> <?php $k = $_POST['number']; // to specify the number of dice rolls rather than allowing the user // to choose, change the second block to $i <= [number of rolls] // then remove the form unless you like frustrating people :-) for ($i = 1; $i <= $k; $i++) { $roll = mt_rand(1,6); echo "<img src='dice{$roll}.gif' alt='$roll' /> "; // the following 25 lines can be removed, as well as the very first line // of the code, if you don't care about tracking the results if ($roll == 1) { $_SESSION['one'] = $_SESSION['one'] + 1; } else if ($roll == 2) { $_SESSION['two'] = $_SESION['two'] + 1; } else if ($roll == 3) { $_SESSION['three'] = $_SESSION['three'] + 1; } else if ($roll == 4) { $_SESSION['four'] = $_SESSION['four'] + 1; } else if ($roll == 5) { $_SESSION['five'] = $_SESSION['five'] + 1; } else if ($roll == 6) { $_SESSION['six'] = $_SESSION['six'] +1; } } ?> <p><i>How many dice to roll</i></p> <form action="<?php $_SERVER['PHP_SELF'] ?>" method="post"> <!-- this can only be an integer --> <input type="text" name='number' /> <input type="submit" value="Roll the dice!" /> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
xoligy Posted September 22, 2008 Share Posted September 22, 2008 how many times do you want the user to throw the dice? at a guess just change the value and experiment Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 22, 2008 Author Share Posted September 22, 2008 Only 2 dice, everytime, but I don't understand what I need to change in order to set the number of dice? Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 22, 2008 Share Posted September 22, 2008 Change the line that says $k = $_POST['number'] to $k = 2; Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 22, 2008 Author Share Posted September 22, 2008 Yay! Thank you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.