Jump to content

[SOLVED] Dice Roller Script


twilitegxa

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/125246-solved-dice-roller-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.