Advertisement
Guest User

Untitled

a guest
May 17th, 2012
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.57 KB | None | 0 0
  1. <?php
  2.     if(isset($_GET['e'])){ //If a date is submitted, edit it
  3.         //Load the scores XML file
  4.         $scores = new DOMDocument();
  5.         $scores -> load('scores.xml');
  6.  
  7.         //Get the <Games> tag
  8.         $games = $scores -> getElementsByTagName('Game');
  9.        
  10.         //Loop through each found game
  11.         foreach ($games as $game) {
  12.             $child = $game->getElementsByTagName("Date")->item(0);
  13.             $oldScore = $game->getElementsByTagName("Score")->item(0);
  14.             $oldRow = $game->getElementsByTagName("Row")->item(0);
  15.             $time = $child->nodeValue;
  16.             if($time==$_GET['e']){ //The date is the date asked for.
  17.                 $game -> replaceChild($scores -> createElement("Score", $_GET['score']),$oldScore);
  18.                 $game -> replaceChild($scores -> createElement("Row", $_GET['row']),$oldRow);
  19.             }
  20.         }
  21.        
  22.         //Save again
  23.         $scores -> save('scores.xml');
  24.     }
  25. ?>
  26. <hr>
  27. <?php
  28.     //Load the scores XML file
  29.     $scores = new DOMDocument();
  30.     $scores -> load('scores.xml');
  31.  
  32.     //Get the <Games> tag
  33.     $games = $scores -> getElementsByTagName('Game');
  34.    
  35.     //Loop through each game
  36.     foreach ($games as $game) {
  37.         //Print each with an edit link.
  38.         $time = $game->getElementsByTagName("Date")->item(0)->nodeValue;
  39.         $score = $game->getElementsByTagName("Score")->item(0)->nodeValue;
  40.         $row = $game->getElementsByTagName("Row")->item(0)->nodeValue;
  41.         echo "<h3>".$time . "</h3>
  42.         <form method='get' action=''>
  43.             <input type='hidden' name ='e' value='$time'>
  44.             Score: <input type='text' value='$score' name='score'><br>
  45.             Row: <input type='text' value='$row' name='row'><br>
  46.             <input type='submit' value='edit'>
  47.         </form>
  48.         <hr>";
  49.     }
  50. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement