Witam, chciałbym napisać skrypt który aktualizowałby czasy wyścigów. Napisałem coś "po swojemu" lecz nie bardzo chce to działać jak należy.. tzn. Czasy niby się dodają lecz tylko dla jednej osoby (wiem, że zamiast polecenia INSERT będę musiał zrobić UPDATE lecz na chwilę obecną po prostu testuję to wszystko). Mógłby mi ktoś podpowiedzieć jak w łatwy sposób dodać te dane do mysql tak aby były one dla każdego gracza?

dla przykładu:
  1. LP. Nick Czas Marka Model
  2. 1 NICK1 0:01:39.328 FORD RTRX69
  3. 2 NICK2 0:01:41.191 LAMBORGHINI MURCIELAGO640
  4. 3 NICK3 0:01:46.089 MITSUBISHI ECLIPSEELITE



i chciałbym aby te dane w podobny sposób zapisywały się do bazy danych ponieważ na chwilę obecną dodaje mi się tylko ostatni rekord, którym w tym wypadku jest:

  1. 3 NICK3 0:01:46.089 MITSUBISHI ECLIPSEELITE


To co na chwilę obecną napisałem: (wiem pewnie jest bez sensu, można zrobić to inaczej i o wiele łatwiej i przejrzyściej i przede wszystkim by działało, lecz ja dopiero się uczę i z czasem gdy już coraz więcej będę wiedział będę to wszystko upraszczałsmile.gif )

  1. <?php
  2. include 'leaderboards.php';
  3.  
  4. //optional comment out or delete
  5.  
  6. // The POST URL and parameters
  7. $trasa = $_GET['trasa'];
  8. $tryb = $_GET['tryb'];
  9. $trasa2 = 'trasa_' .$trasa.'';
  10.  
  11. $sql_host = '----------------';
  12. $sql_user = '----------------';
  13. $sql_password = '--------------';
  14. $sql_baza = '---------------------';
  15.  
  16. if (mysql_connect($sql_host, $sql_user, $sql_password) and mysql_select_db($sql_baza)) {
  17. $zapytanie = mysql_query("SELECT * FROM drivers");
  18. if ($zapytanie) {
  19.  
  20. $rezultat = ''; // inicjalizujemy zmienna
  21. while ($wynik = mysql_fetch_array($zapytanie)) {
  22. if ($rezultat != '') {
  23. // rezultat NIE jest pusty, wiec dodajemy przecinek i spacje
  24. $rezultat .= ','; // to jest to samo co: $rezultat = $rezultat . ', ';
  25. }
  26.  
  27. $rezultat .= $wynik["nick"];
  28.  
  29. }
  30.  
  31. } else {
  32. echo "Nie można wykonać zapytania!";
  33. }
  34. }
  35.  
  36.  
  37. $request = 'http://world.needforspeed.com/SpeedAPI/ws/game/1/nfsw/leaderboards?et='.$tryb.'&eid='.$trasa.'&lt=1&dn='.$rezultat.'&output=xml';
  38.  
  39. // POST the curl session object
  40. $session = curl_init($request);
  41.  
  42. // Set the POST options.
  43. curl_setopt ($session, CURLOPT_POST, true);
  44. curl_setopt ($session, CURLOPT_POSTFIELDS, $request);
  45. curl_setopt($session, CURLOPT_HEADER, true);
  46. curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
  47.  
  48. // Do the POST and then close the session
  49. $response = curl_exec($session);
  50. curl_close($session);
  51.  
  52. // POST HTTP Status code from the response
  53. $status_code = array();
  54. preg_match('/\d\d\d/', $response, $status_code);
  55.  
  56. // Check for errors
  57. switch( $status_code[0] ) {
  58. case 200:
  59. // Success
  60. break;
  61. case 503:
  62. die('Service unavailable. An internal problem prevented us from returning data to you.');
  63. break;
  64. case 403:
  65. die('Forbidden. You do not have permission to access this resource, or are over your rate limit.');
  66. break;
  67. case 409:
  68. die('<font color="white"> Nie można pobrać danych z serwerów EA. Prawdopodobnie serwery są wyłączone.</font> ');
  69. break;
  70. case 400:
  71. // You may want to fall through here and read the specific XML error
  72. die('Bad request. The parameters passed to the service did not match as expected. The exact error is returned in the XML response.');
  73. break;
  74. default:
  75. die('Your call returned an unexpected HTTP status of:' . $status_code[0]);
  76. }
  77.  
  78. // POST the XML from the response, bypassing the header
  79. if (!($xml = strstr($response, '<?xml'))) {
  80. $xml = null;
  81. }
  82.  
  83. ?>
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90. <?php
  91. // Output the XML
  92.  
  93. $worldLeaderboard = simplexml_load_string($xml);
  94.  
  95. foreach ($worldLeaderboard->worldLeaderboard as $world)
  96. {
  97. $playername = $world['personaName'];
  98. $playertime = $world['eventDuration'];
  99. $playerrank = $world['rank'];
  100.  
  101. $tekst = $world['make'];
  102. $tekst2 = $world['carName'];
  103.  
  104. $playermake = str_replace('CAR_MANU_', '', $tekst);
  105. $playercar = str_replace('CAR_MDL_', '', $tekst2);
  106.  
  107.  
  108.  
  109. }
  110. ?>
  111.  
  112. <?php
  113. require 'config.php'; // Dołącz plik konfiguracyjny i połączenie z bazą
  114.  
  115.  
  116. if ( isset($_POST['send']) && $_POST['send'] == 1) {
  117. // Zabezpiecz dane z formularza przed kodem HTML i ewentualnymi atakami SQL Injection
  118. $nick = mysql_real_escape_string(htmlspecialchars($_POST['nick']));
  119. $czas = mysql_real_escape_string(htmlspecialchars($_POST['czas']));
  120. $marka = mysql_real_escape_string(htmlspecialchars($_POST['marka']));
  121. $model = mysql_real_escape_string(htmlspecialchars($_POST['model']));
  122. $pozycja = mysql_real_escape_string(htmlspecialchars($_POST['pozycja']));
  123.  
  124.  
  125.  
  126.  
  127. // Zapisz dane do bazy
  128. mysql_query("INSERT INTO $trasa2 (nick, tryb, czas, marka, model, pozycja) VALUES('$nick', '$tryb', '$czas', '$marka', '$model', '$pozycja') ;") or die ('<p class="error">Wystąpił błąd w zapytaniu i nie udało się dodać kierowcy do statystyk.</p>');
  129.  
  130. echo '<p class="success">Statystyki zostały poprawnie zaktualizowane.</p>';
  131. }
  132.  
  133. ?>
  134.  
  135. <form method="post" action="">
  136. <input type="hidden" name="nick" id="nick" value="<?php echo $rezultat; ?>" />
  137. <input type="hidden" name="tryb" id="tryb" value="<?php echo $tryb; ?>" />
  138. <input type="hidden" name="czas" id="czas" value="<?php echo $playertime; ?>" />
  139. <input type="hidden" name="marka" id="marka" value="<?php echo $playermake; ?>" />
  140. <input type="hidden" name="model" id="model" value="<?php echo $playercar; ?>" />
  141. <input type="hidden" name="pozycja" id="pozycja" value="<?php echo $playerrank; ?>" />
  142.  
  143. <input type="hidden" name="send" value="1" />
  144. <input type="submit" value="Aktualizuj statystyki" />
  145. </form>
  146. <?php
  147. include 'dol.php';
  148. ?>
  149.  
  150.  


bazę danych zrobiłem takim poleceniem:

  1. CREATE TABLE trasa_299 (id int NOT NULL AUTO_INCREMENT, nick char(30), czas char(15), marka char(30), model char(30), pozycja char(4), tryb char(10), PRIMARY KEY(id))


odświeżam

odświeżam 2