Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]Powielanie danych po konwersji do JSON
rafik73
post
Post #1





Grupa: Zarejestrowani
Postów: 182
Pomógł: 0
Dołączył: 19.03.2014

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


Witam
Nie wiem jak to ugryźć. Podaję kod:

  1. $result=mysqli_query($mysqli , "SELECT * FROM tssk , tssk_points_2018 , planfri
  2. WHERE
  3. pf_data = data_punktu
  4. AND nr_punktu = point_2018
  5. AND pf_data BETWEEN '$first' AND '$last'
  6. ORDER BY pf_data ASC , nr_punktu ASC
  7. ")
  8. or die(mysqli_error($mysqli));
  9.  
  10.  
  11. while($row=mysqli_fetch_array($result)) {
  12.  
  13. $no=$row['no'];
  14. $date=$row['data_punktu'];
  15. $ts[]=$row['point_time_text_2018'];
  16.  
  17. $posts[$date] = array(
  18. 'no'=> $no,
  19. 'date'=> $date,
  20. 'ts'=> $ts
  21. );
  22.  
  23. }
  24.  
  25. $fp = fopen('results.json', 'w');
  26. fwrite($fp, json_encode($posts, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_ERROR_UTF8));
  27. fclose($fp);


Wynik:


  1. {
  2. "2018-01-01": {
  3. "no": "0",
  4. "date": "2018-01-01",
  5. "ts": [
  6. "4 min lub mniej",
  7. "4 min",
  8. "3 min lub mniej",
  9. "6 min lub mniej"
  10. ]
  11. },
  12. "2018-01-08": {
  13. "no": "0",
  14. "date": "2018-01-08",
  15. "ts": [
  16. "4 min lub mniej",
  17. "4 min",
  18. "3 min lub mniej",
  19. "6 min lub mniej",
  20. "4 min lub mniej",
  21. "2 min lub mniej",
  22. "5 min",
  23. "6 min lub mniej"
  24. ]
  25. },
  26. "2018-01-15": {
  27. "no": "0",
  28. "date": "2018-01-15",
  29. "ts": [
  30. "4 min lub mniej",
  31. "4 min",
  32. "3 min lub mniej",
  33. "6 min lub mniej",
  34. "4 min lub mniej",
  35. "2 min lub mniej",
  36. "5 min",
  37. "6 min lub mniej",
  38. "4 min lub mniej",
  39. "2 min lub mniej",
  40. "3 min lub mniej",
  41. "5 min"
  42. ]
  43. },
  44. "2018-01-22": {
  45. "no": "0",
  46. "date": "2018-01-22",
  47. "ts": [
  48. "4 min lub mniej",
  49. "4 min",
  50. "3 min lub mniej",
  51. "6 min lub mniej",
  52. "4 min lub mniej",
  53. "2 min lub mniej",
  54. "5 min",
  55. "6 min lub mniej",
  56. "4 min lub mniej",
  57. "2 min lub mniej",
  58. "3 min lub mniej",
  59. "5 min",
  60. "4 min lub mniej",
  61. "3 min lub mniej",
  62. "3 min lub mniej",
  63. "6 min lub mniej"
  64. ]
  65. },
  66. "2018-01-29": {
  67. "no": "0",
  68. "date": "2018-01-29",
  69. "ts": [
  70. "4 min lub mniej",
  71. "4 min",
  72. "3 min lub mniej",
  73. "6 min lub mniej",
  74. "4 min lub mniej",
  75. "2 min lub mniej",
  76. "5 min",
  77. "6 min lub mniej",
  78. "4 min lub mniej",
  79. "2 min lub mniej",
  80. "3 min lub mniej",
  81. "5 min",
  82. "4 min lub mniej",
  83. "3 min lub mniej",
  84. "3 min lub mniej",
  85. "6 min lub mniej",
  86. "4 min lub mniej",
  87. "3 min lub mniej",
  88. "3 min lub mniej",
  89. "6 min lub mniej"
  90. ć
  91. }
  92. }


Problem tkwi w tym, że wartości pola ts są 'zapamiętywane' i powielane w kolejnych rekordach. Jego wartości
są w bazie danych przypisane względem daty (pf_data) i powinno ich być po 4 na każdą datę.
Nie mogę z tym dojsc do ładu.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
rafik73
post
Post #2





Grupa: Zarejestrowani
Postów: 182
Pomógł: 0
Dołączył: 19.03.2014

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


Tworzę tam tabelę, bez tego wyświetla pojedyncze rekordy.
Bo jak dam:

  1. $ts=$row['point_time_text_2018'];


wyświetla:

  1. {
  2. "2018-01-01": {
  3. "no": "0",
  4. "date": "2018-01-01",
  5. "ts": "6 min lub mniej"
  6. },
  7. "2018-01-08": {
  8. "no": "0",
  9. "date": "2018-01-08",
  10. "ts": "6 min lub mniej"
  11. },
  12. "2018-01-15": {
  13. "no": "0",
  14. "date": "2018-01-15",
  15. "ts": "5 min"
  16. },
  17. "2018-01-22": {
  18. "no": "0",
  19. "date": "2018-01-22",
  20. "ts": "6 min lub mniej"
  21. },
  22. "2018-01-29": {
  23. "no": "0",
  24. "date": "2018-01-29",
  25. "ts": "6 min lub mniej"
  26. }
  27. }



Chciałbym uzyskać taki efekt:

  1. {
  2. "2018-01-01": {
  3. "no": "0",
  4. "date": "2018-01-01",
  5. "ts": [
  6. "4 min lub mniej",
  7. "4 min",
  8. "3 min lub mniej",
  9. "6 min lub mniej"
  10. ]
  11. },
  12. "2018-01-08": {
  13. "no": "0",
  14. "date": "2018-01-08",
  15. "ts": [
  16.  
  17. "4 min lub mniej",
  18. "2 min lub mniej",
  19. "5 min",
  20. "6 min lub mniej"
  21. ]
  22. },
  23. "2018-01-15": {
  24. "no": "0",
  25. "date": "2018-01-15",
  26. "ts": [
  27.  
  28. "4 min lub mniej",
  29. "2 min lub mniej",
  30. "3 min lub mniej",
  31. "5 min"
  32. ]
  33. },
  34. "2018-01-22": {
  35. "no": "0",
  36. "date": "2018-01-22",
  37. "ts": [
  38.  
  39. "4 min lub mniej",
  40. "3 min lub mniej",
  41. "3 min lub mniej",
  42. "6 min lub mniej"
  43. ]
  44. },
  45. "2018-01-29": {
  46. "no": "0",
  47. "date": "2018-01-29",
  48. "ts": [
  49.  
  50. "4 min lub mniej",
  51. "3 min lub mniej",
  52. "3 min lub mniej",
  53. "6 min lub mniej"
  54. ]
  55. }
  56. }


Ten post edytował rafik73 9.04.2018, 20:25: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: 17.10.2025 - 10:28