Jump to content

Dice roller help


Dmark91

Recommended Posts

Hey guys. I'm new around here, and I come to you to get some help on a coding. I have made a program that selects two variable via the POST function and generates a set amount of random numbers between 1 and $B. That thing works like a charm and it places them all neatly in a table, but now I want to get on with the program and make it count the amount of all the numbers specified in variable $C.

 

EXAMPLE:

 

Generated 9 random numbers with a value between 1 and 10, echoing out the following:

9

8

2

6

4

7

3

10

5

 

Now I want it to count the numbers 8 and 9, telling me how many there are.

 

If I can get this to work, I then want it to count the amount of 10's, add them to the amount of 8's and 9's, plus reroll them, add the following 8's and 9's, then repeat the process of counting and rerolling the 10's, then adding the 8's and 9's. Any of you have an idea of how to make this work?

Link to comment
Share on other sites

Remembered that it might help if I posted my current code.

 

This is the page that posts information into the other page, which in turn generates the numbers.

<html>
<base target="content">
<body>
<center>
<form action='rolls.php' method='POST'>
	Number of sides: <input type='text' name='A'><br>
	Number of dies: <input type='text' name='B'><br>
	Mark and count the following numbers: <input type='text' name='C'>
	<input type='submit' value='Roll dem dices!'
</form>
</center>
</body>
</html>

 

And this is the page that in turn uses the posted values and generates the numbers. This is where I want the count of the numbers to be.

<html>
<head>
<?php
$A=$_REQUEST['A'];
if ($A=="")
$State="InputData";
else
$A=$_POST['A'];
$B=$_POST['B'];
$C=$_POST['C'];
$State="Beregn"
?>
</head>
<body>
<table border="1">
<?php
for ($i=0; $i<$B; $i++)
{
echo "<tr>";
echo "<td>";
$value = rand (1, $A);
echo $value;
echo "</td>";
echo "</tr>";
}	
?>
</table>
</body>
</html>

Link to comment
Share on other sites

You really think I haven't tried?  ;)

 

I've tried to add this at the end of page 2:

$result=count($C)
echo $result

 

But then it just says one, no matter what I do.

 

Then I tried this:

echo count($C)

¨

Which just gave me an error that made the entire program crash.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.