Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]update tablicy session
john_doe
post
Post #1





Grupa: Zarejestrowani
Postów: 873
Pomógł: 25
Dołączył: 24.07.2005

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


Witam, mam tablice $_SESSION, print_r z niej daje
Array ( [3] => Array ( [id] => 1 [ile] => 1 ) [4] => Array ( [id] => 2 [ile] => 1 ) )

chcę edytować i updateować klucze 'ile'
narazie nie wychodzi ale mam tyle

  1. <form method="POST" action="editExec.php">
  2.  
  3. <?php
  4.    foreach($_SESSION['koszyk'] as $value)
  5.    {
  6.        print 'idP: ' . $value['id'].'=> ilosc: <input type="text" name="updateTab[]" value="' . $value['ile'].'" /><br>';
  7.    }
  8.  
  9. ?>
  10. <input type="submit" value="zmien" name="edytuj" />
  11. </form>


elementy w sumię będą się nadpisywać kolejno czyli 1szy z jednej tablicy = 1szy z drugiej tablicy

Myślałem, że przejdę przez to imlodem ale lipa. prosze o wskazówki

potem takie coś ale też nie działa

  1. <?php
  2. foreach($_SESSION['koszyk'] as $value)
  3.        {
  4.            $i = 0;
  5.            print $value['ile'].' = ' . $_POST['updateTab'][$i];
  6.            $value['ile'] = $_POST['updateTab'][$i];
  7.            $i++;
  8.        }
  9. ?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
john_doe
post
Post #2





Grupa: Zarejestrowani
Postów: 873
Pomógł: 25
Dołączył: 24.07.2005

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


napisałem coś takiego
  1. <form method="POST" action="editExec.php">
  2.  
  3. <?php
  4.    $iter = -1;
  5.    
  6.    foreach($_SESSION['koszyk'] as $value)
  7.    {
  8.        $iter++;
  9.        
  10.        print 'idP: ' . $value['id'].'=> ilosc: <input type="text" name="updateTab['.$iter.'][id]" value="' . $value['ile'].'" /><br>';
  11.        
  12.        
  13.    }
  14.  
  15. ?>
  16. <input type="submit" value="Zmien" name="edytuj" />
  17. </form>


po odebraniu formularza i zapodaniu

  1. <?php
  2. print_r($_POST['updateTab']);
  3.  
  4. print '<br>';        
  5.  
  6. print_r($_SESSION['koszyk']);
  7.  
  8. $_SESSION['koszyk'] = array_merge($_SESSION['koszyk'], $_POST['updateTab']);
  9.  
  10. print '<br>';        
  11.  
  12. print_r($_SESSION['koszyk']);
  13. ?>


Array ( [0] => Array ( [id] => 55 ) )
Array ( [0] => Array ( [id] => 2 [ile] => 1 ) )
Array ( [0] => Array ( [id] => 2 [ile] => 1 ) [1] => Array ( [id] => 55 ) ) //tutaj po merge

czyli nie kosi

Ten post edytował john_doe 2.07.2009, 22:29:44
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: 5.10.2025 - 23:16