Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Brak zapisu w tabeli wszystkich rekordów z pliku xml
slawekxx
post
Post #1





Grupa: Zarejestrowani
Postów: 189
Pomógł: 2
Dołączył: 28.08.2010

Ostrzeżenie: (0%)
-----


Witam, mam mały problem z zapisaniem wielu rekordów z pliku xml jednocześnie , poniżej jest mój skrypt zapisuje on jeden rekord i tylko ostatni z pliku xml , co muszę poprawić aby zapisywał wszystkie rekordy do bazy mysql ?


  1.  
  2. //Parsal
  3.  
  4. $markers = simplexml_load_file('http://www.meteo.gr/WFSail/templates/Gdata2.xml');
  5. foreach ($markers->GROUND_STATIONS as $pogoda) {
  6. $tmp = $pogoda->attributes();
  7. $tmp['station_name'];
  8. $tmp['station_id'];
  9. $tmp['od_date'];
  10. $tmp['od_time'];
  11. $tmp['lat'];
  12. $tmp['long'];
  13.  
  14. }
  15.  
  16. // odbieramy dane z xml dane stacji
  17.  
  18. $station_name = $tmp['station_name'];
  19. $station_id = $tmp['station_id'];
  20. $od_date=$tmp['od_date'];
  21. $od_time=$tmp['od_time'];
  22. $lat = $tmp['lat'];
  23. $lng = $tmp['long'];
  24.  
  25.  
  26. foreach ($pogoda->OBSERVATIONS_GREECE as $rozne){
  27. $tmp = $rozne->attributes();
  28. $tmp['wind_dir'];
  29. $tmp['wind_force'];
  30. $tmp['temperature'];
  31. $tmp['pressure'];
  32. }
  33.  
  34. //Odbieramy dane z pliku xml dane pomiaru
  35.  
  36.  
  37. $wind_dir=$tmp['wind_dir'];
  38. $wind_force=$tmp['wind_force'];
  39. $temperature=$tmp['temperature'];
  40. $pressure=$tmp['pressure'];
  41.  
  42.  
  43. foreach ($rozne->OBSERVATIONS_PHENOMENA as $tekst){
  44. $tmp = $tekst->attributes();
  45. $tmp['DIRTEXT'];
  46. $tmp['descr'];
  47. }
  48.  
  49. //Odbieramy dane z pliku xml dane pomiaru czesc druga
  50.  
  51. $DIRTEXT=$tmp['DIRTEXT'];
  52. $descr=$tmp['descr'];
  53.  
  54. if($station_name and $station_id and $od_date and $od_time and $lat and $lng and $wind_dir and $wind_force and $temperature and $pressure and $DIRTEXT
  55.  
  56. and $descr) {
  57.  
  58. // łączymy się z bazą danych
  59.  
  60. $connection = mysql_connect('host', 'login', 'hasło')
  61. or die('Brak połączenia z serwerem MySQL');
  62. $db = mysql_select_db('baza', $connection)
  63. or die('Nie mogę połączyć się z bazą danych');
  64.  
  65. // dodaje dane stacji do bazy
  66.  
  67. $ins = mysql_query("INSERT INTO tablica SET
  68.  
  69. station_name='$station_name',station_id='$station_id',dzien='$od_date',czas='$od_time',lat='$lat',lng='$lng',wind_dir='$wind_dir',wind_force='$wind_forc
  70.  
  71. e',temperature='$temperature',pressure='$pressure',DIRTEXT='$DIRTEXT',descr='$descr'");
  72.  
  73. if($ins) echo "Rekord został dodany poprawnie";
  74. else echo "Błąd nie udało się dodać nowego rekordu";
  75.  
  76.  
  77. }


Problem prawie rozwiązany, tylko teraz dziwnie zapisują mi się dane w tabeli a mianowicie w trzech rekordach są dane z jednej stacji to jest kod
  1. // łšczymy się z bazš danych
  2.  
  3. $connection = mysql_connect('host', 'login', 'hasło')
  4. or die('Brak połšczenia z serwerem MySQL');
  5. $db = mysql_select_db('baza', $connection)
  6. or die('Nie mogę połšczyć się z bazš danych');
  7.  
  8. //Parsal
  9.  
  10. $markers = simplexml_load_file('http://www.meteo.gr/WFSail/templates/Gdata2.xml');
  11. foreach ($markers->GROUND_STATIONS as $pogoda) {
  12. $tmp = $pogoda->attributes();
  13. $tmp['station_name'];
  14. $tmp['station_id'];
  15. $tmp['od_date'];
  16. $tmp['od_time'];
  17. $tmp['lat'];
  18. $tmp['long'];
  19.  
  20. $ins = mysql_query("INSERT INTO nazwa tabeli SET station_name='$station_name',station_id='$station_id',dzien='$od_date',czas='$od_time',lat='$lat',lng='$lng'");
  21.  
  22. // odbieramy dane z xml dane stacji
  23.  
  24. $station_name = $tmp['station_name'];
  25. $station_id = $tmp['station_id'];
  26. $od_date=$tmp['od_date'];
  27. $od_time=$tmp['od_time'];
  28. $lat = $tmp['lat'];
  29. $lng = $tmp['long'];
  30.  
  31. foreach ($pogoda->OBSERVATIONS_GREECE as $rozne){
  32. $tmp = $rozne->attributes();
  33. $tmp['wind_dir'];
  34. $tmp['wind_force'];
  35. $tmp['temperature'];
  36. $tmp['pressure'];
  37.  
  38. $ins = mysql_query("INSERT INTO nazwa tabeli SET wind_dir='$wind_dir',wind_force='$wind_force',temperature='$temperature',pressure='$pressure'");
  39. //Odbieramy dane z pliku xml dane pomiaru
  40.  
  41. $wind_dir=$tmp['wind_dir'];
  42. $wind_force=$tmp['wind_force'];
  43. $temperature=$tmp['temperature'];
  44. $pressure=$tmp['pressure'];
  45.  
  46. foreach ($rozne->OBSERVATIONS_PHENOMENA as $tekst){
  47. $tmp = $tekst->attributes();
  48. $tmp['DIRTEXT'];
  49. $tmp['descr'];
  50. }
  51. }
  52. }
  53. //Odbieramy dane z pliku xml dane pomiaru czesc druga
  54.  
  55. $DIRTEXT=$tmp['DIRTEXT'];
  56. $descr=$tmp['descr'];
  57. $ins = mysql_query("INSERT INTO nazwa tabeli SET DIRTEXT='$DIRTEXT',descr='$descr'");
  58.  
  59. if($station_name and $station_id and $od_date and $od_time and $lat and $lng and $wind_dir and $wind_force and $temperature and $pressure and $DIRTEXT and $descr) {
  60.  
  61.  
  62. if($ins) echo "Rekord został dodany poprawnie";
  63. else echo "Błšd nie udało się dodać nowego rekordu";
  64. }


Ten post edytował slawekxx 5.09.2010, 10:26:14
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 16:42