Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Zmiana liczby produktow w koszyku
dolar
post
Post #1





Grupa: Zarejestrowani
Postów: 92
Pomógł: 0
Dołączył: 19.10.2016

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


Niestety napotkalam problem. Podczas zmiany ilosci produktu w koszyku nie potrafie przyporzadkowac zmiany do danego produktu i zmieniaja mi sie wszystkie produkty na raz. Oto moj kod:

  1. <form method="post">
  2. <table id="produkty">
  3. <tr>
  4. <th>Id</th>
  5. <th>Kategoria</th>
  6. <th>Nazwa</th>
  7. <th>Rozmiar</th>
  8. <th>Cena</th>
  9. <th>Ilosc</th>
  10. <th>Usuń</th>
  11. <th>Suma</th>
  12. </tr>

  1.  
  2. if (array_key_exists('ilosc', $_POST)){
  3. $numer = (int)$_POST['ilosc'];
  4. } else {
  5. $numer=10;
  6. }
  7.  
  8. if (array_key_exists('minus', $_POST)){
  9. $numer--;
  10. }
  11. if (array_key_exists('plus', $_POST)){
  12. $numer++;
  13. }
  14.  
  15.  
  16.  
  17. foreach ($_SESSION['koszyk'] as $key => $produkt) {
  18. $key=$key+1;
  19. echo "<tr>";
  20. echo "<td>" . $key. "</td>";
  21. echo "<td>" . $produkt['kategoria'] . "</td>";
  22. echo "<td>" . $produkt['nazwa'] . "</td>";
  23. echo "<td>" . $produkt['rozmiar'] . "</td>";
  24. echo "<td>" . $produkt['cena'] . "</td>";
  25. echo '<td>';
  26. echo '<button type="submit" name="minus">-</button>';
  27. echo '<input type="text" name="ilosc" id="ilosc" value='.$numer.'>';
  28. echo '<button type="submit" name="plus">+</button>';
  29. echo "</td>";
  30. echo "<td><button type='submit' name='usun' value='usun'>Usun</button></td>";
  31. echo "</tr>";
  32. }
  33. }
  34.  
  35.  
  36.  


Ktos cos? Bo serio od wczoraj utknelam sad.gif

Ten post edytował dolar 7.12.2016, 16:30:09
Go to the top of the page
+Quote Post
viking
post
Post #2





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


Produkty zapisuj najlepiej w sesji po id produktu zamiast automatycznej numeracji (według posta z wczoraj). Czyli $_SESSION['koszyk'][tutaj_id] = [tablica parametrów przykładowo 'ilosc' => 0]. Wtedy łatwo będzie się można odwołać do danego produktu.


--------------------
Go to the top of the page
+Quote Post
dolar
post
Post #3





Grupa: Zarejestrowani
Postów: 92
Pomógł: 0
Dołączył: 19.10.2016

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


Chyba sie porwalam na zbyt gleboka wode... :/
Go to the top of the page
+Quote Post
viking
post
Post #4





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


Kwestia przyzwyczajenia. Tablice są łatwe w zrozumieniu i obsłudze.


--------------------
Go to the top of the page
+Quote Post
dolar
post
Post #5





Grupa: Zarejestrowani
Postów: 92
Pomógł: 0
Dołączył: 19.10.2016

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


Wlasnie dlatego probuje je dobrze zrozumiec i zrobic koszyk na tablicach. Mimo Twojej wskazowki i tak dalej nie potrafie ruszyc. Myslalam ze automatyczna numeracja jest w porzadku to raz a dwa wydawalo mi sie ze po value=$key w buttonie bedzie skrypt wiedzial o jaki produkt chodzi a jednak tak sie nie stalo.

A czy mozna jakos zmodyfikowac moj sposob myslenia tak aby to jakos dzialalo? Z automatyczna numeracja?
Go to the top of the page
+Quote Post
viking
post
Post #6





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


A submitując ten formularz masz gdzieś pole z kluczem? Po co robisz $key=$key+1?


--------------------
Go to the top of the page
+Quote Post
dolar
post
Post #7





Grupa: Zarejestrowani
Postów: 92
Pomógł: 0
Dołączył: 19.10.2016

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


Robilam tak i tez mi nie dziala. ten $key+1 robie po to zeby mi na stronie sie pokazywalo nie od 0 liczba produktow tylko od 1.

  1.  
  2.  
  3. if (array_key_exists('ilosc', $_POST)){
  4. $numer = (int)$_POST['ilosc'];
  5. } else {
  6. $numer=1;
  7. }
  8.  
  9. if (array_key_exists('minus', $_POST) && $numer>0){
  10. $numer--;}
  11. }
  12. if (array_key_exists('plus', $_POST)){
  13. $numer++;
  14. }
  15.  
  16. foreach ($_SESSION['koszyk'] as $key => $produkt) {
  17. $key=$key+1;
  18. echo "<tr>";
  19. echo "<td>" . $key. "</td>";
  20. echo "<td>" . $produkt['kategoria'] . "</td>";
  21. echo "<td>" . $produkt['nazwa'] . "</td>";
  22. echo "<td>" . $produkt['rozmiar'] . "</td>";
  23. echo "<td>" . $produkt['cena'] . "</td>";
  24. echo '<td>';
  25. echo '<button type="submit" name="minus" value="'.$key.'">-</button>';
  26. echo '<input type="text" name="ilosc" id="ilosc" value='.$numer.'>';
  27. echo '<button type="submit" name="plus" value="'.$key.'">+</button>';
  28. echo "</td>";
  29. echo "<td><button type='submit' name='usun' value='.$key.'>Usun</button></td>";
  30. echo "</tr>";
  31.  
  32. }



Go to the top of the page
+Quote Post
viking
post
Post #8





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


Dla usuń brakuje "". Tym sposobem, gdyby działało, a z kodu nie wynika co jest źle, dane były by zmieniane dla kolejnego produktu a nie faktycznego z pętli. Daj tylko dla echo +1.


--------------------
Go to the top of the page
+Quote Post
dolar
post
Post #9





Grupa: Zarejestrowani
Postów: 92
Pomógł: 0
Dołączył: 19.10.2016

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


Hmmm zmienialm to echo i dalej jak nie dziala tak nie dziala tzn dziala, ale przy dodawaniu lub odejmowaniu liczby produku zmieniaja mi sie wszystkie produkty zamiast ten jeden edytowany sad.gif. Przeciez o ile dobrze mysle to dodajac do buttonow value=$key kazdy powinien miec dopasowany klucz danego produktu a mimo to nie widzi mi tego.

Ten post edytował dolar 8.12.2016, 11:17:53
Go to the top of the page
+Quote Post
viking
post
Post #10





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


A w jaki sposób robisz aktualizację? Powinno być coś w stylu
if dodanie $_SESSION['koszyk'][$_POST['plus']]['ilosc']++;

Łatwiej było by stworzyć ukryty input z wartością klucza.


--------------------
Go to the top of the page
+Quote Post
dolar
post
Post #11





Grupa: Zarejestrowani
Postów: 92
Pomógł: 0
Dołączył: 19.10.2016

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


Wlasnie nie uzywalam nigdy inputa hidden i nie potrafiego zastosowac ale wlasnie czytam o nim i moze faktycznie trzeba by bylo jego uzyz? A Twojego kodu za bardzo nie rozumiem biggrin.gif
Go to the top of the page
+Quote Post
viking
post
Post #12





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


Input hidden to po prostu standardowy input którego nie widać na stronie. Dane z niego są tak samo przesyłane w formularzu. Pamiętaj tylko że to wcale nie oznacza, że jego wartość nie może być zmieniona np. przez włamywacza.

Robisz wtedy:
  1. <input type=hidden name=key value=$key/>


Po stronie PHP możesz odczytać:

  1. $productKey = isset($_POST['key']) ? (int) $_POST['key'] : false;
  2.  
  3. if (isset($_POST['plus']) && $productKey !== false) {
  4. $_SESSION['koszyk'][$productKey]['ilosc']++;
  5. }


Ten post edytował viking 8.12.2016, 12:36:54


--------------------
Go to the top of the page
+Quote Post
dolar
post
Post #13





Grupa: Zarejestrowani
Postów: 92
Pomógł: 0
Dołączył: 19.10.2016

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


Kombinuje i kombinuje ale nadal nie moge dojsc jak by moglo wygladac to rozwiazanie sad.gif. Czy udalo Ci sie to zrobic tak ze faktycznie kod dziala?
Go to the top of the page
+Quote Post
viking
post
Post #14





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


Ja kodu nie robiłem. Nie znam założeń ani funkcjonalności a tu jest tylko fragment. Pokaż jak to robisz, jak wygląda koszyk dla przykladowego produktu.


--------------------
Go to the top of the page
+Quote Post
dolar
post
Post #15





Grupa: Zarejestrowani
Postów: 92
Pomógł: 0
Dołączył: 19.10.2016

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


Produkt:

  1.  
  2. <?php
  3.  
  4. $produkty = array(
  5. 'kategoria' => 'bluzki',
  6. 'nazwa' => 'Lewis',
  7. 'rozmiar' => 'xl',
  8. 'cena' => 20.50,
  9. 'ilosc' => ''
  10. ),
  11. 'kategoria' => 'spodnie',
  12. 'nazwa' => 'Lee',
  13. 'rozmiar' => 31,
  14. 'cena' => 99.50
  15. ),
  16. 'kategoria' => 'bluzki',
  17. 'nazwa' => 'Modoo',
  18. 'rozmiar' => 'l',
  19. 'cena' => 29.90
  20. ),
  21. 'kategoria' => 'spodnie',
  22. 'nazwa' => 'Wrangler',
  23. 'rozmiar' => 28,
  24. 'cena' => 100.50
  25. ),
  26. 'kategoria' => 'bluzki',
  27. 'nazwa' => 'Cropp',
  28. 'rozmiar' => 'l/xl',
  29. 'cena' => 29.50
  30. ),
  31. 'kategoria' => 'spodnie',
  32. 'nazwa' => 'BigStar',
  33. 'rozmiar' => 30,
  34. 'cena' => 89.50
  35. )
  36. );
  37.  
  38. if (array_key_exists('wybrany_produkt', $_POST)){
  39. $idProduktu=$_POST['wybrany_produkt'];
  40. $_SESSION['koszyk'][] = $produkty[$idProduktu];
  41. echo '<div id="komunikat">';
  42. echo "Produkt dodano do koszyka!";
  43. echo '</div>';
  44.  
  45. }
  46.  
  47.  
  48.  
  49. ?>
  50.  
  51. <html>
  52. <head>
  53. <meta charset="UTF-8">
  54.  
  55. <style>
  56. #komunikat {
  57. position: absolute;
  58. width: 100%;
  59. text-align: center;
  60. top: 50px;
  61. font-weight: bolder;
  62. color: #8b0000;
  63. }
  64.  
  65. #produkty {
  66. width: 100%;
  67. text-align: center;
  68.  
  69. }
  70.  
  71. #produkty th {
  72. padding: 4px;
  73. background-color: #eee;
  74. }
  75.  
  76. #produkty td {
  77. padding: 4px;
  78. }
  79.  
  80. h1 {
  81. margin-top: 100px;
  82. text-align: center;
  83. }
  84.  
  85. #obrazek {
  86. width: 150px;
  87. position: absolute;
  88. top:0px;
  89. right:0px;
  90.  
  91. }
  92.  
  93. #koszyk {
  94. width: 150px;
  95. height: 80px;
  96. }
  97.  
  98. #liczbaProduktow {
  99. width: 20px;
  100. height: 20px;
  101. text-align: center;
  102. position: absolute;
  103. left:0px;
  104. top:-15px;
  105. font-weight: bolder;
  106. }
  107.  
  108.  
  109.  
  110. </style>
  111. </head>
  112. <body>
  113.  
  114. <div id="obrazek">
  115. <a href=""><img src="""/></a>
  116. <p id="liczbaProduktow">
  117. <?php
  118. if (array_key_exists('koszyk', $_SESSION)){
  119. $i=count($_SESSION['koszyk']);
  120. echo $i;
  121. }
  122.  
  123. ?>
  124.  
  125. </p>
  126. </div>
  127.  
  128. <h1>Produkty</h1>
  129. <form method="post">
  130. <table id="produkty">
  131. <tr>
  132. <th>Kategoria</th>
  133. <th>Nazwa</th>
  134. <th>Rozmiar</th>
  135. <th>Cena</th>
  136. <th>Opcje</th>
  137. </tr>
  138. <?php
  139. foreach ($produkty as $key => $produkt) {
  140. echo "<tr>";
  141. echo "<td>" . $produkt['kategoria'] . "</td>";
  142. echo "<td>" . $produkt['nazwa'] . "</td>";
  143. echo "<td>" . $produkt['rozmiar'] . "</td>";
  144. echo "<td>" . $produkt['cena'] . "</td>";
  145. echo '<td><button type="submit" name="wybrany_produkt" value="'.$key.'">Kup</button></td>';
  146. echo "</tr>";
  147. }
  148. ?>
  149. </table>
  150. </form>
  151.  
  152.  
  153. </body>
  154.  
  155. <script>
  156. setTimeout(function(){
  157. document.getElementById('komunikat').style.display = 'none';
  158. }, 2000);
  159. </script>
  160. </html>
  161.  
  162.  



Koszyk

  1.  
  2. <?php
  3.  
  4.  
  5. if (!array_key_exists('koszyk', $_SESSION)) {
  6. $_SESSION['koszyk'] = array();
  7. }
  8.  
  9.  
  10. ?>
  11.  
  12. <html>
  13. <head>
  14. <meta charset="UTF-8">
  15. <style>
  16.  
  17. #produkty {
  18. width: 100%;
  19. text-align: center;
  20.  
  21. }
  22.  
  23. #produkty th {
  24. padding: 4px;
  25. background-color: #eee;
  26. }
  27.  
  28. #produkty td {
  29. padding: 4px;
  30. }
  31.  
  32.  
  33. h1 {
  34. margin-top: 50px;
  35. text-align: center;
  36. }
  37.  
  38. #napisPusty {
  39. width:150px;
  40. margin: auto;
  41. }
  42.  
  43. #ilosc {
  44. width:25px;
  45. text-align: center;
  46. }
  47.  
  48. </style>
  49. </head>
  50. <body>
  51. <h1>Koszyk</h1>
  52.  
  53. <?php
  54.  
  55.  
  56. if (empty($_SESSION['koszyk'])){
  57. echo "<div id='napisPusty'>Twoj koszyk jest pusty</div>";
  58. } else {
  59. ?>
  60. <form method="post">
  61. <table id="produkty">
  62. <tr>
  63. <th>Id</th>
  64. <th>Kategoria</th>
  65. <th>Nazwa</th>
  66. <th>Rozmiar</th>
  67. <th>Cena</th>
  68. <th>Ilosc</th>
  69. <th>Usuń</th>
  70. <th>Suma</th>
  71. </tr>
  72. <?php
  73.  
  74.  
  75. if (array_key_exists('ilosc', $_POST)){
  76. $numer = (int)$_POST['ilosc'];
  77. } else {
  78. $numer=1;
  79. }
  80.  
  81. if (array_key_exists('minus', $_POST) && $numer>0){
  82. $numer--;}
  83. }
  84. if (array_key_exists('plus', $_POST)){
  85. $numer++;
  86. }
  87.  
  88. foreach ($_SESSION['koszyk'] as $key => $produkt) {
  89.  
  90. echo "<tr>";
  91. echo "<td>" . $key. "</td>";
  92. echo "<td>" . $produkt['kategoria'] . "</td>";
  93. echo "<td>" . $produkt['nazwa'] . "</td>";
  94. echo "<td>" . $produkt['rozmiar'] . "</td>";
  95. echo "<td>" . $produkt['cena'] . "</td>";
  96. echo '<td>';
  97. echo '<button type="submit" name="minus" value="'.$key.'">-</button>';
  98. echo '<input type="text" name="ilosc" id="ilosc" value='.$numer.'>';
  99. echo '<button type="submit" name="plus" value="'.$key.'">+</button>';
  100. echo "</td>";
  101. echo "<td><button type='submit' name='usun' value='".$key."'>Usun</button></td>";
  102. echo "</tr>";
  103.  
  104. }
  105.  
  106. if (array_key_exists('usun', $_POST)){
  107. unset($_SESSION['koszyk'][$key]);
  108. }
  109.  
  110.  
  111. ?>
  112.  
  113. </table>
  114.  
  115. </body>
  116. </html>


Z unset ten sam problem sad.gif
Zaczelam kombinowac cos zeby dodac jeszcze do tablicy $produkty jeszcze jedna kategorie 'ilosc' => 0, ale tez nie wiem jak to ugryzc
Go to the top of the page
+Quote Post
viking
post
Post #16





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


Coś takiego mniej wiecej
  1. <?php
  2.  
  3. $produkty = array(
  4. 'kategoria' => 'bluzki',
  5. 'nazwa' => 'Lewis',
  6. 'rozmiar' => 'xl',
  7. 'cena' => 20.50
  8. ),
  9. 'kategoria' => 'spodnie',
  10. 'nazwa' => 'Lee',
  11. 'rozmiar' => 31,
  12. 'cena' => 99.50
  13. ),
  14. 'kategoria' => 'bluzki',
  15. 'nazwa' => 'Modoo',
  16. 'rozmiar' => 'l',
  17. 'cena' => 29.90
  18. ),
  19. 'kategoria' => 'spodnie',
  20. 'nazwa' => 'Wrangler',
  21. 'rozmiar' => 28,
  22. 'cena' => 100.50
  23. ),
  24. 'kategoria' => 'bluzki',
  25. 'nazwa' => 'Cropp',
  26. 'rozmiar' => 'l/xl',
  27. 'cena' => 29.50
  28. ),
  29. 'kategoria' => 'spodnie',
  30. 'nazwa' => 'BigStar',
  31. 'rozmiar' => 30,
  32. 'cena' => 89.50
  33. )
  34. );
  35.  
  36. if (array_key_exists('wybrany_produkt', $_POST)){
  37. $idProduktu=$_POST['wybrany_produkt'];
  38. if (isset($_SESSION['koszyk'][$idProduktu])) {
  39. $_SESSION['koszyk'][$idProduktu]['ilosc']++;
  40. } else {
  41. $_SESSION['koszyk'][$idProduktu] = $produkty[$idProduktu];
  42. $_SESSION['koszyk'][$idProduktu]['ilosc'] = 1;
  43. }
  44. echo '<div id="komunikat">';
  45. echo "Produkt dodano do koszyka!";
  46. echo '</div>';
  47.  
  48. }
  49.  
  50.  
  51.  
  52. ?>
  53.  
  54. <html>
  55. <head>
  56. <meta charset="UTF-8">
  57.  
  58. <style>
  59. #komunikat {
  60. position: absolute;
  61. width: 100%;
  62. text-align: center;
  63. top: 50px;
  64. font-weight: bolder;
  65. color: #8b0000;
  66. }
  67.  
  68. #produkty {
  69. width: 100%;
  70. text-align: center;
  71.  
  72. }
  73.  
  74. #produkty th {
  75. padding: 4px;
  76. background-color: #eee;
  77. }
  78.  
  79. #produkty td {
  80. padding: 4px;
  81. }
  82.  
  83. h1 {
  84. margin-top: 100px;
  85. text-align: center;
  86. }
  87.  
  88. #obrazek {
  89. width: 150px;
  90. position: absolute;
  91. top:0px;
  92. right:0px;
  93.  
  94. }
  95.  
  96. #koszyk {
  97. width: 150px;
  98. height: 80px;
  99. }
  100.  
  101. #liczbaProduktow {
  102. width: 20px;
  103. height: 20px;
  104. text-align: center;
  105. position: absolute;
  106. left:0px;
  107. top:-15px;
  108. font-weight: bolder;
  109. }
  110.  
  111.  
  112.  
  113. </style>
  114. </head>
  115. <body>
  116.  
  117. <div id="obrazek">
  118. <a href=""><img src="""/></a>
  119. <p id="liczbaProduktow">
  120. <?php
  121. if (array_key_exists('koszyk', $_SESSION)){
  122. echo count($_SESSION['koszyk']);
  123. }
  124.  
  125. ?>
  126.  
  127. </p>
  128. </div>
  129.  
  130. <h1>Produkty</h1>
  131. <form method="post">
  132. <table id="produkty">
  133. <tr>
  134. <th>Kategoria</th>
  135. <th>Nazwa</th>
  136. <th>Rozmiar</th>
  137. <th>Cena</th>
  138. <th>Opcje</th>
  139. </tr>
  140. <?php
  141. foreach ($produkty as $key => $produkt) {
  142. echo "<tr>";
  143. echo "<td>" . $produkt['kategoria'] . "</td>";
  144. echo "<td>" . $produkt['nazwa'] . "</td>";
  145. echo "<td>" . $produkt['rozmiar'] . "</td>";
  146. echo "<td>" . $produkt['cena'] . "</td>";
  147. echo '<td><button type="submit" name="wybrany_produkt" value="'.$key.'">Kup</button></td>';
  148. echo "</tr>";
  149. }
  150. ?>
  151. </table>
  152. </form>
  153.  
  154.  
  155. </body>
  156.  
  157. <script>
  158. setTimeout(function(){
  159. document.getElementById('komunikat').style.display = 'none';
  160. }, 2000);
  161. </script>
  162. </html>


  1. <?php
  2.  
  3. if (!array_key_exists('koszyk', $_SESSION)) {
  4. $_SESSION['koszyk'] = array();
  5. }
  6. ?>
  7.  
  8. <html>
  9. <head>
  10. <meta charset="UTF-8">
  11. <style>
  12.  
  13. #produkty {
  14. width: 100%;
  15. text-align: center;
  16.  
  17. }
  18.  
  19. #produkty th {
  20. padding: 4px;
  21. background-color: #eee;
  22. }
  23.  
  24. #produkty td {
  25. padding: 4px;
  26. }
  27.  
  28.  
  29. h1 {
  30. margin-top: 50px;
  31. text-align: center;
  32. }
  33.  
  34. #napisPusty {
  35. width:150px;
  36. margin: auto;
  37. }
  38.  
  39. #ilosc {
  40. width:25px;
  41. text-align: center;
  42. }
  43.  
  44. </style>
  45. </head>
  46. <body>
  47. <h1>Koszyk</h1>
  48.  
  49. <?php
  50.  
  51. if (empty($_SESSION['koszyk'])){
  52. echo "<div id='napisPusty'>Twoj koszyk jest pusty</div>";
  53. }
  54. ?>
  55. <form method="post">
  56. <table id="produkty">
  57. <tr>
  58. <th>Id</th>
  59. <th>Kategoria</th>
  60. <th>Nazwa</th>
  61. <th>Rozmiar</th>
  62. <th>Cena</th>
  63. <th>Ilosc</th>
  64. <th>Usuń</th>
  65. <th>Suma</th>
  66. </tr>
  67. <?php
  68. if (isset($_POST['ilosc']) && isset($_POST['aktualizuj'])) {
  69. foreach($_POST['ilosc'] as $key => $ilosc) {
  70. if ($ilosc > 0) {
  71. $_SESSION['koszyk'][$key]['ilosc'] = (int) $ilosc;
  72. }
  73. }
  74. }
  75.  
  76. if (isset($_POST['plus'])) {
  77. $_SESSION['koszyk'][$_POST['plus']]['ilosc']++;
  78. } elseif (isset($_POST['minus'])) {
  79. $_SESSION['koszyk'][$_POST['minus']]['ilosc']--;
  80. if ($_SESSION['koszyk'][$_POST['minus']]['ilosc'] < 1) {
  81. unset($_SESSION['koszyk'][$_POST['minus']]);
  82. }
  83. }
  84.  
  85. if (array_key_exists('usun', $_POST)){
  86. unset($_SESSION['koszyk'][$_POST['usun']]);
  87. }
  88.  
  89. foreach ($_SESSION['koszyk'] as $key => $produkt) {
  90.  
  91. echo "<tr>";
  92. echo "<td>" . $key . "</td>";
  93. echo "<td>" . $produkt['kategoria'] . "</td>";
  94. echo "<td>" . $produkt['nazwa'] . "</td>";
  95. echo "<td>" . $produkt['rozmiar'] . "</td>";
  96. echo "<td>" . $produkt['cena'] . "</td>";
  97. echo '<td>';
  98. echo '<button type="submit" name="minus" value="'.$key.'">-</button>';
  99. echo '<input type="text" name="ilosc['.$key.']" id="ilosc" value="'. $produkt['ilosc'] .'"/>';
  100. echo '<button type="submit" name="plus" value="'.$key.'">+</button>';
  101. echo '<button type="submit" name="aktualizuj">Aktualizuj ilość</button>';
  102. echo "</td>";
  103. echo "<td><button type='submit' name='usun' value='".$key."'>Usun</button></td>";
  104. echo "<td>" . $produkt['cena'] * $produkt['ilosc'] . "</td>";
  105. echo "</tr>";
  106.  
  107. }
  108.  
  109. ?>
  110.  
  111. </table>
  112. </form>
  113. </body>
  114. </html>


--------------------
Go to the top of the page
+Quote Post
dolar
post
Post #17





Grupa: Zarejestrowani
Postów: 92
Pomógł: 0
Dołączył: 19.10.2016

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


Viking - dziekuje smile.gif Dziala, lekko zmodyfikowalam i wszystko smiga
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 20.08.2025 - 11:06