Dmark91 Posted February 16, 2011 Share Posted February 16, 2011 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? Quote Link to comment Share on other sites More sharing options...
Dmark91 Posted February 16, 2011 Author Share Posted February 16, 2011 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> Quote Link to comment Share on other sites More sharing options...
Dmark91 Posted February 16, 2011 Author Share Posted February 16, 2011 Bump Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 16, 2011 Share Posted February 16, 2011 You need to try, and then we can help. We won't do it for you. Quote Link to comment Share on other sites More sharing options...
Dmark91 Posted February 16, 2011 Author Share Posted February 16, 2011 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. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 16, 2011 Share Posted February 16, 2011 If you've tried things, you have to post them, and the actual errors. There's a PHP function called array_count_values. That's what you need. Quote Link to comment Share on other sites More sharing options...
Dmark91 Posted February 16, 2011 Author Share Posted February 16, 2011 Cool. Thanks, I'll try that in the morning ^^ Sorry if I came across a little rude before. I'm kinda tired. 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.