If anyone knows of the Nintendo Wii Virtual Console; that's good, I am making a 'simple' calculator that allows you (regardless of region) to find how many Wii points you would have after you downloaded some retro games onto the Wii. All I need is help with a foreach loop. Here is the PHP file (that does the interpreting of the form):

<?PHP
// ======================================================================
=====
// NORTH AMERICA
// ======================================================================
=====
$_PRICES['NES']  = 500;
$_PRICES['SNES']  = 800;
$_PRICES['N64']  = 1000;
$_PRICES['GEN']  = 800;
$_PRICES['TURBO']  = 600;
//---------------------------------------------------------------------------
// SOUTH AMERICA
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// EUROPE
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// ASIA
//---------------------------------------------------------------------------
/*
$_PRICES['FAM']  = 500;
$_PRICES['SFAM']  = 800;
$_PRICES['N64']  = 1000;
$_PRICES['MASTER']  = 800;
$_PRICES['PC']   = 600;
*/
//---------------------------------------------------------------------------
// OTHER
//---------------------------------------------------------------------------

$total = 0;

foreach ($_PRICES as $current_game) 
{

}

?>

What follows is the form, form.html.

<html>
<head>
<title>Virtual Console Calculator</title>
Welcome one, welcome all!
To this Virtual Console Calculator. This script is to help you decide on what Virtual Console games you'd like to download onto your Nintendo Wii. Simply check the boxes of the game(s) you'd like to download &amp; (how many wii points you'd have after the last download is done), and input (at the bottom) amount of Wii points you have, and submit.
<body>
<form action=wii.php method=POST>
<table border=0 width=100%>
<tr>
<td><input type="checkbox" /><strong>N</strong>intendo <strong>E</strong>ntertainment <strong>S</strong>ystem
<td><input type="checkbox" name="NES []" />Donkey Kong </td>
<td><input type="checkbox" name="NES []" />Mario Bros </td>
<td><input type="checkbox" name="NES []" />Pinball </td>
<td><input type="checkbox" name="NES []" />Soccer </td>
<td><input type="checkbox" name="NES []" />Solomon's Key </td>
<td><input type="checkbox" name="NES []" />Legend of Zelda </td>
<td><input type="checkbox" name="NES []" />Wario's Woods </td>
<td><input type="checkbox" name="NES []" />Donkey Kong Jr </td>
<td><input type="checkbox" name="NES []" />Ice Hockey </td>
<td><input type="checkbox" name="NES []" />Tennis </td>
<td><input type="checkbox" name="NES []" />Super Mario Bros </td>
<td><input type="checkbox" name="NES []" />Baseball </td>
<td><input type="checkbox" name="NES []" />Urban Champion </td>
</tr>
<tr>
<td><input type="checkbox" /><strong>S</strong>uper <strong>N</strong>intendo <strong>E</strong>ntertainment <strong>S</strong>ystem</td>
<td><input type="checkbox" name="SNES []" />F-Zero </td>
<td><input type="checkbox" name="SNES []" />SimCity </td>
<td><input type="checkbox" name="SNES []" />Street Fighter II: The World Warrior </td>
<td><input type="checkbox" name="SNES []" />Super Castlevania IV </td>
</tr>
<tr>
<td><input type="checkbox" /><strong>N</strong>intendo <strong>64</strong>
<td><input type="checkbox" name="N64 []" />Mario 64 </td>
</tr>
<tr>
<td><input type="checkbox" name="GEN []" />Sega Genesis
<td><input type="checkbox" name="GEN []" />Altered Beast </td>
<td><input type="checkbox" name="GEN []" />Sonic The Hedgehog </td>
<td><input type="checkbox" name="GEN []" />Ecco the Dolphin </td>
<td><input type="checkbox" name="GEN []" />Golden Axe </td>
<td><input type="checkbox" name="GEN []" />Columns </td>
<td><input type="checkbox" name="GEN []" />Ristar </td>
<td><input type="checkbox" name="GEN []" />Dr. Robotnik's Mean Bean Machine </td>
<td><input type="checkbox" name="GEN []" />Gunstar Heroes </td>
<td><input type="checkbox" name="GEN []" />Space Harrier II </td>
<td><input type="checkbox" name="GEN []" />ToeJam & Earl </td>
</tr>
<tr>
<td><input type="checkbox" name="TURBO []" />Turbo Grafix 16 </td>
<td><input type="checkbox" name="TURBO []" />Bomberman '93 </td>
<td><input type="checkbox" name="TURBO []" />Bonk's Adventure </td>
<td><input type="checkbox" name="TURBO []" />Super Star Soldier </td>
<td><input type="checkbox" name="TURBO []" />Victory Run </td>
<td><input type="checkbox" name="TURBO []" />Alien Crush </td>
<td><input type="checkbox" name="TURBO []" />Military Madness </td>
<td><input type="checkbox" name="TURBO []" />R-Type </td>
</tr>
</table>
<input type="text" value="" /> <input type="submit" value="Calculate Wii points" /> <input type="reset" value="Reset this form" />
</form>
</body>
</head>
</html>

The script does NOT use functions, if-statements (of any kind), just:

$POST
$
PRICES
$current_game
$total
+=

That is it! Nothing else (I think, I can't rememeber)

    $total = 0;

    foreach ($_PRICES as $current_game)
    {
    $total += $current_game;
    }

      What the damn hell do I have to do to get it though people heads?! Though that does use $total, += & $current_game; I also said it uses $_POST as wii.php handles what form.html.

        dlf wrote:

        What the damn hell do I have to do to get it though people heads?!

        Losing the attitude might be a start.

        So let me make sure I understand you - you want people to be able to check various boxes of games they want to download. All you need the script to do is to take all of their selections and come up with a point total, adding different "point" amounts based on the type of the game checked? If so, here's what I'd do:

        1. Remove all spaces between the game name and the [] brackets in your HTML. Example: name="SNES []" becomes name="SNES[]".

        2. Use something like this:

          $points = 0;
          foreach ($_PRICES as $gametype => $value) { 
          	if(!isset($_POST[$gametype]))
          		continue;
          	else {
          		foreach($_POST[$gametype] as $selection)
          			$points += $value;
          	}
          }
          
          echo "You earned a total of $points points.";

          One reason I am angry is people do not read what it does not use. This script makes no use if statements (of any kind). Just a foreach loop:

          foreach ($PRICES as $current_game {
          // $
          POST, $_PRICES (I thkink), $current_game, $total, +=
          }

          and that is ALL, NOTHING MORE!.

            I'm confused... are you trying to get help with a script, or are you trying to play a "Guess-this-script" game with us? I posted code (rare that I simply spoonfeed code) that does what you described, and is really very simple - no advanced functions/syntax/methods/etc.

            If you're so adamant in telling us what this script is, why not write it yourself?

              I can do VERY little in PHP, and I am trying to help people with this but as I can not do harder PHP than printing things to the screen (echo & prints) and simple functions . . .

              All I need is the loop 'done' that just uses four/five things; but all replies to my topics do use not all of them, $POST is always left out even though I clearly (IMO) say $POST is used in the loop.

                dlf wrote:

                I can do VERY little in PHP

                And that's the beauty of seeing different people solve a problem in different methods (such as on this help forum) - you see things from new perspectives, and (hopefully) learn new things. One of my personal goals - and I think many others here share this - is to help people not only by finding a solution to their problems but also to teach them something.

                dlf wrote:

                $_POST is always left out

                shrug I didn't leave it out. In fact, I threw my snippet onto my test server to verify it worked. If you're looking for a different solution (which, to me, I don't think you're going to find a solution as simple as you're looking for, but that's nothing more than my opinion) because you don't understand my code snippet, that's where the 'learning' part that I mentioned above comes in. All you have to do is say something like "thanks, can you explain that code now?" or something similar, and I (or anyone else who feels like annotating my code before I see your reply) will gladly explain the code, step-by-step. How does that help you? Two ways: one, you get the code to solve your problem; two, you (hopefully) learn something that you can apply to other PHP scripts in the future.

                  Nice that you are apreciating people trying to help you out, it will surely help you to get additional help.

                  It seems to me that the first thing you should do is some tutorials. Then find the manual and read up on the foreach loop. Then you can do it yourself.

                    Perhaps something without the basic language construct of an if would help. Here's one that only uses two "advanced" functions:
                    1.) [man]foreach[/man]/b - Itterates through each item of an array
                    2.) [man]count[/man]/b - Counts the number of elements in an array starting at 1.

                    Using those two functions you can go over 1 array, count the number of each type of system's game, and then calculate the total. Very very easy:

                    <?php
                    	$_PRICES = array(
                    		'NES' => 500,
                    		'SNES' => 800,
                    		'N64' => 1000,
                    		'GEN' => 800,
                    		'TURBO' => 600,
                    	);
                    
                    $total_points = 0;
                    
                    foreach($_POST['games'] AS $type=>$arr)
                    {
                    	$multiplier = count($arr);
                    	$total_points += $_PRICES[$type]*$multiplier;
                    }
                    
                    echo 'You would stand to lose ', $total_points, ' Wii points.';
                    ?>
                    <html>
                    <head>
                    <title>Virtual Console Calculator</title>
                    
                    <script type="text/javascript" language="Javascript"><!-- // --><![CDATA[
                    
                    function getElementsByClassName(oElm, strTagName, strClassName)
                    {
                    	var arrElements = (strTagName == "*" && oElm.all) ? oElm.all : oElm.getElementsByTagName(strTagName);
                    	var arrReturnElements = new Array();
                    	strClassName = strClassName.replace(/\-/g, "\\-");
                    	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
                    	var oElement;
                    	for (var i=0; i<arrElements.length; i++)
                    	{
                    		oElement = arrElements[i];
                    		if(oRegExp.test(oElement.className))
                    		{
                    			arrReturnElements.push(oElement);
                    		}
                    	}
                    
                    	return(arrReturnElements);
                    }
                    
                    function selectAll(oElm, strTagName, cName, group)
                    {
                    	var elmnts = getElementsByClassName(oElm, strTagName, cName);
                    
                    	for(var i=0; i<elmnts.length; i++)
                    	{
                    		if(group.checked==true)
                    			elmnts[i].checked=true;
                    		else
                    			elmnts[i].checked=false;
                    	}
                    }
                    
                    // ]]></script>
                    </head>
                    <body>
                    Welcome one, welcome all!
                    To this Virtual Console Calculator. This script is to help you decide on what Virtual Console games you'd like to download onto your Nintendo Wii. Simply check the boxes of the game(s) you'd like to download &amp; (how many wii points you'd have after the last download is done), and input (at the bottom) amount of Wii points you have, and submit.
                    <form action='' method='POST'>
                    <table border='0' width='100%'>
                    	<tr>
                    		<th colspan='5' style="text-align: left;"><input type="checkbox" onClick="selectAll(document, 'input', 'NES', this);" /><strong>N</strong>intendo <strong>E</strong>ntertainment <strong>S</strong>ystem</th>
                    	</tr>
                    	<tr>
                    		<td><input type="checkbox" name="games[NES][]" class="NES" />Donkey Kong </td>
                    		<td><input type="checkbox" name="games[NES][]" class="NES" />Mario Bros </td>
                    		<td><input type="checkbox" name="games[NES][]" class="NES" />Pinball </td>
                    		<td><input type="checkbox" name="games[NES][]" class="NES" />Soccer </td>
                    		<td><input type="checkbox" name="games[NES][]" class="NES" />Solomon's Key </td>
                    	</tr>
                    	<tr>
                    		<td><input type="checkbox" name="games[NES][]" class="NES" />Legend of Zelda </td>
                    		<td><input type="checkbox" name="games[NES][]" class="NES" />Wario's Woods </td>
                    		<td><input type="checkbox" name="games[NES][]" class="NES" />Donkey Kong Jr </td>
                    		<td><input type="checkbox" name="games[NES][]" class="NES" />Ice Hockey </td>
                    		<td><input type="checkbox" name="games[NES][]" class="NES" />Tennis </td>
                    	</tr>
                    	<tr>
                    		<td><input type="checkbox" name="games[NES][]" class="NES" />Super Mario Bros </td>
                    		<td><input type="checkbox" name="games[NES][]" class="NES" />Baseball </td>
                    		<td><input type="checkbox" name="games[NES][]" class="NES" />Urban Champion </td>
                    	</tr>
                    	<tr>
                    		<td colspan="5"></td>
                    	</tr>
                    	<tr>
                    		<th colspan='5' style="text-align: left;"><input type="checkbox" onClick="selectAll(document, 'input', 'SNES', this);" /><strong>S</strong>uper <strong>N</strong>intendo <strong>E</strong>ntertainment <strong>S</strong>ystem</th>
                    	</tr>
                    	<tr>
                    		<td><input type="checkbox" name="games[SNES][]" class="SNES" />F-Zero </td>
                    		<td><input type="checkbox" name="games[SNES][]" class="SNES" />SimCity </td>
                    		<td><input type="checkbox" name="games[SNES][]" class="SNES" />Street Fighter II: The World Warrior </td>
                    		<td><input type="checkbox" name="games[SNES][]" class="SNES" />Super Castlevania IV </td>
                    		<td></td>
                    	</tr>
                    	<tr>
                    		<td colspan="5"></td>
                    	</tr>
                    	<tr>
                    		<th colspan="5" style="text-align: left;"><input type="checkbox" onClick="selectAll(document, 'input', 'N64', this);" /><strong>N</strong>intendo <strong>64</strong></th>
                    	</tr>
                    	<tr>
                    		<td><input type="checkbox" name="games[N64][]" class="N64" />Mario 64 </td>
                    		<td></td>
                    		<td></td>
                    		<td></td>
                    		<td></td>
                    	</tr>
                    	<tr>
                    		<td colspan="5"></td>
                    	</tr>
                    	<tr>
                    		<th colspan="5" style="text-align: left;"><input type="checkbox" onClick="selectAll(document, 'input', 'GEN', this);" />Sega Genesis</th>
                    	</tr>
                    	<tr>
                    		<td><input type="checkbox" name="games[GEN][]" class="GEN" />Altered Beast </td>
                    		<td><input type="checkbox" name="games[GEN][]" class="GEN" />Sonic The Hedgehog </td>
                    		<td><input type="checkbox" name="games[GEN][]" class="GEN" />Ecco the Dolphin </td>
                    		<td><input type="checkbox" name="games[GEN][]" class="GEN" />Golden Axe </td>
                    		<td><input type="checkbox" name="games[GEN][]" class="GEN" />Columns </td>
                    	</tr>
                    	<tr>
                    		<td><input type="checkbox" name="games[GEN][]" class="GEN" />Ristar </td>
                    		<td><input type="checkbox" name="games[GEN][]" class="GEN" />Dr. Robotnik's Mean Bean Machine </td>
                    		<td><input type="checkbox" name="games[GEN][]" class="GEN" />Gunstar Heroes </td>
                    		<td><input type="checkbox" name="games[GEN][]" class="GEN" />Space Harrier II </td>
                    		<td><input type="checkbox" name="games[GEN][]" class="GEN" />ToeJam & Earl </td>
                    	</tr>
                    	<tr>
                    		<td colspan="5"></td>
                    	</tr>
                    	<tr>
                    		<th colspan="5" style="text-align: left;"><input type="checkbox" onClick="selectAll(document, 'input', 'TURBO', this);" />Turbo Grafix 16 </th>
                    	</tr>
                    	<tr>
                    		<td><input type="checkbox" name="games[TURBO][]" class="TURBO" />Bomberman '93 </td>
                    		<td><input type="checkbox" name="games[TURBO][]" class="TURBO" />Bonk's Adventure </td>
                    		<td><input type="checkbox" name="games[TURBO][]" class="TURBO" />Super Star Soldier </td>
                    		<td><input type="checkbox" name="games[TURBO][]" class="TURBO" />Victory Run </td>
                    		<td><input type="checkbox" name="games[TURBO][]" class="TURBO" />Alien Crush </td>
                    	</tr>
                    	<tr>
                    		<td><input type="checkbox" name="games[TURBO][]" class="TURBO" />Military Madness </td>
                    		<td><input type="checkbox" name="games[TURBO][]" class="TURBO" />R-Type </td>
                    	</tr>
                    </table>
                    <input type="text" value="" /> <input type="submit" name="submit" value="Calculate Wii points" /> <input type="reset" value="Reset this form" />
                    </form>
                    </body>
                    </head>
                    </html>

                    Note: I updated your HTML to be valid. I also added a little Javascript so that you can just select the system name, and it'd select all subsequent games for that system.

                    See it in action!!
                    Follow Me to calculate your Wii!!!

                      All very nice, I do like the JS effect yet I get a parse error:

                      Parse error: syntax error, unexpected $end in /home/dbzlotrf/public_html/CODING/CONSOLE/wii.php on line 55

                      When trying to submit form.html.

                      <?PHP
                      
                      if(isset($_POST['games']) && !empty($_POST['submit']))
                      {
                          $_PRICES = array(
                              'NES'		=>	500,
                              'SNES'	=>	800,
                              'N64'		=>	1000,
                              'GEN'		=>	800,
                              'TURBO'	=>	600,
                          );
                      
                      $total_points = 0;
                      
                      foreach($_POST['games'] AS $type=>$arr)
                      {
                          $multiplier = count($arr);
                          $total_points += $_PRICES[$type]*$multiplier;
                      }
                      
                      echo 'You would stand to lose ', $total_points, ' Wii points.';
                      ?>

                      ?> is line 22.

                      EDIT: Modified it so the code is parsed as PHP for you. ~bpat1434

                        bpat simply forgot the closing }

                        <?php 
                        if(isset($_POST['games']) && !empty($_POST['submit'])) 
                        { 
                            $_PRICES = array( 
                                'NES' => 500, 
                                'SNES' => 800, 
                                'N64' => 1000, 
                                'GEN' => 800, 
                                'TURBO' => 600, 
                            ); 
                        
                        $total_points = 0; 
                        
                        foreach($_POST['games'] AS $type=>$arr) 
                        { 
                            $multiplier = count($arr); 
                            $total_points += $_PRICES[$type]*$multiplier; 
                        } 
                        
                        echo 'You would stand to lose ', $total_points, ' Wii points.'; 
                        }
                        ?> 

                          I updated the script. You said you didn't want If statements. So it contains no If statements.

                          I also updated the online demo. Added some more stuff to it, and made it easier to differentiate between the systems and games.

                            Very nice, oringinally I wanted (and had before server failure), where you'd select the games & input amount of Wii points you had. Submit and it would output what'd you would have left.

                              And that's what my demo does..... the only thing you don't have coded is the text input. But that's something you can play around with.... If you follow the link to the demo I posted, you can now see the code and use the demo. Just click the little tab at the top that says "Show Source". Then to hide it, just click "Hide Source".

                                Well what-ever the heck you did is nice. How the heck did you get the the 'caluations' like that? That (I think) people would like. As I did think of 'making' this to help people.

                                  I edited my above post.

                                  Added (From above):

                                  bpat1434 wrote:

                                  If you follow the link to the demo I posted, you can now see the code and use the demo. Just click the little tab at the top that says "Show Source". Then to hide it, just click "Hide Source".

                                    I also just thought: Since this is all regions and all games (for all the systems that you can download games of). When more games are added (and systems I believe Nintendo is thinking of) were going to have to find a 'more efficent' method of storing the games. By the end of this year 120 games will be downloaded on North-American Wii's.

                                    Multiply that by 5 (for five years --- if the Wii will last that long) --- you get 600 for the current. That's NA alone, if Europe and Asia/Japan get that many I think it's be a lot.

                                    Ideas? SQL? XML? Other(s)?

                                    Oh and if your thinking of putting all the regions 'clumped' together (all NA, Europe & Asia/Japan) games & systems together that'd be FAR to much scrolling. I have (some) idea(s) on that -- On the 'start' screen your presented with a drop-down box of the region selection & when selected it gives you those region games/systems. But that will have to wait

                                      I'd suggest SQL. I'd even set it up like:

                                      Table: regions

                                      • ID_REGION int(11) NOT NULL auto_increment

                                      • region_Name varchar(255) NOT NULL

                                      Table: systems

                                      • ID_SYSTEM int(11) NOT NULL auto_increment

                                      • ID_REGION int(11) NOT NULL

                                      • system_Name varchar(255) NOT NULL

                                      • system_Info smalltext NOT NULL

                                      Table: games

                                      • ID_GAME int(11) NOT NULL auto_increment

                                      • ID_SYSTEM int(11) NOT NULL

                                      • ID_REGION int(11) NOT NULL

                                      • game_title varchar(255) NOT NULL

                                      • game_descrip smalltext(255) NOT NULL

                                      • game_creator varchar(255) NOT NULL

                                      Table: prices

                                      • ID_PRICE int(11) NOT NULL auto_increment

                                      • ID_SYSTEM int(11) NOT NULL

                                      • price_value int(11) NOT NULL

                                      Now, simple queries could tie all this information together, or you could even use one large database. I personally would use the queries. You could then query per system, per game, per region, and per price. Very flexible, and very much what SQL is made for.

                                        Well for the games; their would more likely be thousands as Nintendo & 'supporting companies' released lots of games for the oringinal systems. Would be a bit tiresom to type in

                                        super_mario_all_stars mario varchar (255) NOT NULL
                                        legend_of_Zelda_adventure_of_link varchar (255) NOT NULL

                                        etc for the games. If there was some way to "automatically' (if that's possible) update the page that'd be great.