Results 1 to 7 of 7

Thread: Foreach loop help

  1. #1
    Join Date
    Jan 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Foreach loop help

    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 Code:
    <?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 {

    }

    ?>

    Early December I had help with this same thing from my brother; it went onto a (currently down) 'server' as such I can't get the code but from the 1st calclulator I remember the loop having:

    $_POST in it (I think $_POST['before']), $total, +=, $current_game. And another variable that I can't remember the name or what it was set as.


    Also as I said before the PHP file interpreted a form which is:


    Code:
    <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>

    Think someone could help me? To confusing/long?

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    I think I know what you are trying to accomplish but the code you posted (unless what I'm thinking you want is wrong) makes no sense as to how to accomplish your goal. Try the following code for wii.php:

    Code:
    <?php
    
    $NES = $_REQUEST['NES'];
    $SNES = $_REQUEST['SNES'];
    $N64 = $_REQUEST['N64'];
    $SEGA = $_REQUEST['GEN'];
    $TURBO = $_REQUEST['TURBO'];
    
    $nesCount = count($NES);
    $snesCount = count($SNES);
    $n64Count = count($N64);
    $segaCount = count($SEGA);
    $turboCount = count($turboCount);
    
    $PRICES['NES']  = 500;
    $PRICES['SNES']  = 800;
    $PRICES['N64']  = 1000;
    $PRICES['GEN']  = 800;
    $PRICES['TURBO']  = 600;
    
    $gTotal = ($PRICES['NES'] * $nesCount) + ($PRICES['SNES'] * $snesCount) + ($PRICES['N64'] * $n64Count) + ($PRICES['SEGA'] * $segaCount) + ($PRICES['TURBO'] * $turboCount);
    
    echo 'Grand Total: <b>'.$gTotal.'</b> Points';
    ?>
    Then the following for form.html (you should be able to see the changes I made):

    Code:
    <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><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><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><strong>N</strong>intendo <strong>64</strong>
    <td><input type="checkbox" name="N64[]" />Mario 64 </td>
    </tr>
    <tr>
    <td>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>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="submit" value="Calculate Wii points" /> <input type="reset" value="Reset this form" />
    </form>
    </body>
    </head>
    </html>
    That will produce the following example:

    If on form.html you choose "Donkey Kong", "Donkey Kong, Jr" (both NES), and (on N64) "Mario 64":

    The page will show

    Grand Total: 2000 points
    If you need any further help, or if I am wrong as to what you want to accomplish, let me know.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jan 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Uh no . . I want it output you'd have after you downloaded the games onto the Wii. If I select 3 NES games & input 3,000 Wii points I should get back like "You would have 1500 Wii points after your downloads".

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    So basically what you have now minus (-) what you select, right?
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Jan 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by thetestingsite View Post
    So basically what you have now minus (-) what you select, right?
    I guess, {but} add all the selections together - the Wii points you have.

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Well then, add the following anywhere in form.html:

    Code:
    Current Points: <input type="text" name="current">
    Then the following just underneath "<?php" in wii.php:

    Code:
    $current = $_REQUEST['current'];
    Finally change the following at the bottom of the php (You will see what I have changed in red):

    Code:
    $gTotal = ($PRICES['NES'] * $nesCount) + ($PRICES['SNES'] * $snesCount) + ($PRICES['N64'] * $n64Count) + ($PRICES['SEGA'] * $segaCount) + ($PRICES['TURBO'] * $turboCount);
    
    $gdTotal = $current - $gTotal;
    
    echo 'Grand Total: <b>'.$gdTotal.'</b> Points';
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Jan 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Still doesn't calculate.

    have said COUNTLESS amount(s) of times that I want to use:

    * $_POST*
    * $current_game
    * +=
    * $total

    How hard is it to get that? None of the topics i've posted about this (weather it be here, or other forums) uses $_POST, $current_game. Always changing it around, i'm trying to replicate (dupe/duplicate) exactly the original & the original had those in it.

    * Possibly $_POST['before'] I can't remember.
    That was from another topic I made on another forum. Note that wasn't aimed at anyone at this forum. I am just sick & tierd of pepeople changing what i've seen in the posts of the topics.
    Last edited by dlf; 01-06-2007 at 06:48 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •