Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2011
    Location
    England
    Posts
    23
    Thanks
    9
    Thanked 0 Times in 0 Posts

    I want one php file with all games?

    Hi there,

    I'm currently building a flash-based games website and on a different games website I have seen something like this: game.php?id=11 and I have never known how this is done?.

    I would like to do this as it would save me time having to make multiple pages for the games.

    How is this done?, does it require a database to be done (I'm not botherd if it does, just wondering if it requires one).

    Many thanks for any replies!.

  • #2
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,224
    Thanks
    10
    Thanked 269 Times in 268 Posts
    In its most generic way, it would work like this:
    PHP Code:
    <?php
    switch ($_GET['id'])
    {
    case 
    1:
    // run game 1
    break;
    case 
    2:
    // run game 2
    break;
    default:
    echo 
    "no game specified";
    }
    ?>

  • Users who have thanked tracknut for this post:

    camzenxbt (09-05-2011)

  • #3
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,417
    Thanks
    68
    Thanked 102 Times in 101 Posts
    Here is another way of doing it.

    PHP Code:
    if (isset($_GET['x']))
    {
        
    $x explode(':'$_GET['x']);

        switch(
    $x[0])
        {
            case 
    'game1':
                
    game1();
            break;

                    case 
    'game2':
                
    game2();
            break;
            
      }
    }

    else { 
    menu(); } 
    So if the script was called menu.php and you go to that, it will load the menu function. To get to the others, you use this menu.php?x=game1

  • Users who have thanked myfayt for this post:

    camzenxbt (09-05-2011)

  • #4
    New Coder
    Join Date
    Aug 2011
    Location
    England
    Posts
    23
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thank you for replying!.

    So can I use this for as many games as I want? Can I make more cases like case 3 and case 4 and so on?.

  • #5
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,224
    Thanks
    10
    Thanked 269 Times in 268 Posts
    Quote Originally Posted by camzenxbt View Post
    Thank you for replying!.

    So can I use this for as many games as I want? Can I make more cases like case 3 and case 4 and so on?.
    Yep!

    Dave

  • #6
    New Coder
    Join Date
    Aug 2011
    Location
    England
    Posts
    23
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thank you for your help on this topic!, this code works very good!, ive thanked you for your post aswell .
    Last edited by camzenxbt; 09-05-2011 at 03:11 PM.


  •  

    Tags for this Thread

    Posting Permissions

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