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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts

    Getting Started with Ajax

    I just completed putting up a pretty simple game site that uses php for everything (almost everything). The game is opensource and written by others. I consider myself at rookie at php, and was capable of modifying the game a little bit with some of great help from all of the members here.

    The game constantly sends queries to the database, and then will refresh the screen.

    I know this is a pretty open ended question, and I just bought a book to begin reading this weekend. But I am curious to peoples thoughts on the difficulty level in incorporating ajax into existing php scripts? Something a php rookie should be able to figure out?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Just make sure you understand how PHP works with forms and browser http requests and you'll be able to incorporate Ajax once you understand how Ajax works.

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts
    Thanks for the reply.

    Well, I have a book, and I'm pretty much lost at the moment, but hoping maybe somebody can give a small example of the following. I'm also experimenting with some scripts from zapatec.com

    I have a basic form that says something like:

    "You have 20 armies available to place" The '20' is being read from the database. You simply indicate the number you want to place and press submit.

    I'm trying to have the form submit, and then for the form to update itself, indicating the number of armies you have left. So, if you placed 5, the form will change to say you have 15.

    If it helps, I've included the form below. I think/hope if I can understand how to do that, then I may be able to convert everything else eventually.

    PHP Code:
    <form action="includes/func_addarms.php" method="post" name="statusaction" id="addarmy">
    <br />
    <? // Get the number of armies the player has available to place
        
    $sql 'SELECT armies FROM game_'.$_SESSION['game_id'].' WHERE id = '.$_SESSION['player_id'];
        
    $numarmies get_one($sql);
    ?>

    <input  class="button" type="hidden" name="numarmies" value="<?= $numarmies ?>">
    <input class="button" type="hidden" name="gamestate" value="<?= $gamestate ?>">
    You have <?= $numarmies ?> armies to place.
    <br /><br />

    Armies: <input class="button" name="armies" type="text" size="1"> 
    <select  class="button" name="fromstate">
        <option selected value="invalid">Select a Country:</option>
            <? // Show only the states the current player controls.
            
    while($a_state current($_SESSION['STATES'])){ 
                if(
    $a_state['player'] == $_SESSION['player_id']){ ?>
                    <option value="<?= key($_SESSION['STATES']) ?>"><?= $a_state['name'?></option>    
                <?     
            
    next($_SESSION['STATES']);
                } 
    reset($_SESSION['STATES']); ?>
    </select>
    <br /><br/>
    <input  class="button" type="submit" value="Place Armies">
    </form>


  •  

    Posting Permissions

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