Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Operacje na tablicach
d0m1n1k_
post
Post #1





Grupa: Zarejestrowani
Postów: 208
Pomógł: 3
Dołączył: 13.07.2009
Skąd: Tarnów

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


Witam,
poszukuję rozwiązania następującego problemu.
Chciałbym pobrać dane z czterech tabel w MySQL: Cena hurtowa (CH), Cena detaliczna (CD), Rabat hurtowy (RH), Rabat detaliczny (RD);
Z każdej tabeli pobierane jest: wartość, data obowiązywania.

Przykładowo:

CH: '100, 2015-01-15', '105, 2015-01-10', '100, 2015-01-01';
CD: '120, 2015-01-20', '140, 2015-01-10', '110, 2015-01-02';
RH: '0.1, 2015-01-16', '0.2, 2015-01-09';
RD: '0.05, 2015-01-18', '0.1, 2015-01-09';

Jak widać różne mogą być daty dodania i nie muszą się pokrywać i to samo tyczy się ilości wyciąganych danych.

Zastanawiam się jak mogę wstawić to do szablonu:

  1. [DATA, CH, CD, RH, RD],
  2. ['2015-01-01', 100, null, null, null],
  3. ['2015-01-02', null, 110, null, null],
  4. ['2015-01-09', null, null, 0.2, 0.1],
  5. ['2015-01-10', 105, 140, null, null],
  6. ['2015-01-15', 100, null, null, null],
  7. ['2015-01-16', null, null, 0.1, null],
  8. ['2015-01-18', null, null, null, 0.05],
  9. ['2015-01-20', null, 120, null, null]


Myślałem o array() ale nie wiem jak to dobrze złączyć poprzekształcać - słowem gleba :-//

Z góry dziękuję za pomoc.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
d0m1n1k_
post
Post #2





Grupa: Zarejestrowani
Postów: 208
Pomógł: 3
Dołączył: 13.07.2009
Skąd: Tarnów

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


Super działa.
Delikatnie go "trąciłem" żeby null był małymi literami pisany i poprawiłem $row na $rows wewnątrz while($rows = mysql_fetch_assoc($query)){},
bo wystąpił tam malutki błąd ;-)

Ale znalazłem mały problem. Wyrzuca o jedną wartość za dużo.
  1.  
  2. array(6) {
  3. [0]=>
  4. array(5) {
  5. [0]=>
  6. string(4) "DATA"
  7. [1]=>
  8. string(12) "AVG_RABAT"
  9. [2]=>
  10. string(8) "AVG_CENA"
  11. [3]=>
  12. string(8) "IND_CENA"
  13. [4]=>
  14. string(12) "IND_RABAT"
  15. }
  16. [1]=>
  17. array(6) {
  18. [0]=>
  19. string(10) "2016-01-06"
  20. [1]=>
  21. string(4) "null"
  22. [2]=>
  23. string(6) "0.150"
  24. [3]=>
  25. string(4) "8574"
  26. [4]=>
  27. string(4) "null"
  28. [5]=>
  29. string(4) "null"
  30. }
  31. [2]=>
  32. array(6) {
  33. [0]=>
  34. string(10) "2016-01-23"
  35. [1]=>
  36. string(4) "null"
  37. [2]=>
  38. string(6) "0.175"
  39. [3]=>
  40. string(4) "9740"
  41. [4]=>
  42. string(4) "null"
  43. [5]=>
  44. string(4) "null"
  45. }
  46. [3]=>
  47. array(6) {
  48. [0]=>
  49. string(10) "2015-11-13"
  50. [1]=>
  51. string(4) "null"
  52. [2]=>
  53. string(4) "null"
  54. [3]=>
  55. string(4) "null"
  56. [4]=>
  57. string(5) "11900"
  58. [5]=>
  59. string(6) "0.100"
  60. }
  61. [4]=>
  62. array(6) {
  63. [0]=>
  64. string(10) "2015-11-15"
  65. [1]=>
  66. string(4) "null"
  67. [2]=>
  68. string(4) "null"
  69. [3]=>
  70. string(4) "null"
  71. [4]=>
  72. string(5) "10900"
  73. [5]=>
  74. string(4) "null"
  75. }
  76. [5]=>
  77. array(6) {
  78. [0]=>
  79. string(10) "2016-01-19"
  80. [1]=>
  81. string(4) "null"
  82. [2]=>
  83. string(4) "null"
  84. [3]=>
  85. string(4) "null"
  86. [4]=>
  87. string(4) "null"
  88. [5]=>
  89. string(6) "0.125"
  90. }
  91. }


Pyton_00 => Mega Giga browar dla Ciebie za to jak pomagasz!
Dzięki wielkie, ale błagam, jeśli masz tylko chęć, jeszcze odrobinę pomóż ;-)!

Na marginesie - teraz działa bardzo ładnie.
Omijam jeden element w wyświetlaniu i już

Ten post edytował d0m1n1k_ 26.01.2016, 07:48:23
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: 15.10.2025 - 22:54