Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Tablice i uklad danych
DannyM
post
Post #1





Grupa: Zarejestrowani
Postów: 507
Pomógł: 2
Dołączył: 30.10.2003
Skąd: Poznań

Ostrzeżenie: (10%)
X----


mam taka tablice
Array
(
[name] => Array
(
[0] => Marta
[1] => Jak
)

[nazwisko] => Array
(
[0] => Warta
[1] => Kowalski
)

[email] => Array
(
[0] => marti@ppsdfsd.pl
[1] => kowal@map.pl
)

[password] => Array
(
[0] => chauyec66
[1] => 456tre
)

[Submit] => Zamawiam
)

  1. foreach ($_POST as $klucz => $tablica ) {
  2.  
  3. foreach ($tablica as $nr_wiersza => $wartosc )
  4. echo 'ID: '.$nr_wiersza.' =:'.$wartosc;
  5. }
  6. print "<pre>";
  7. print_r($_POST);
  8. print "</pre>";


Jak przypisac imie do nazwiska itd
Dodatkowo mam Warning: Invalid argument supplied for foreach() in " foreach ($tablica as $nr_wiersza => $wartosc ) "
Dopiero zaczynam z tablicami wiec prosze o wyrozumialosc

Ten post edytował DannyM 17.12.2009, 16:21:18
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 7)
piotrekkr
post
Post #2





Grupa: Zarejestrowani
Postów: 386
Pomógł: 25
Dołączył: 28.09.2005

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


  1. $srcArray = Array
  2. (
  3. 'name' => Array
  4. (
  5. 0 => 'Marta',
  6. 1 => 'Jak',
  7. ),
  8.  
  9. 'nazwisko' => Array
  10. (
  11. 0 => 'Warta',
  12. 1 => 'Kowalski',
  13. ),
  14.  
  15. 'email' => Array
  16. (
  17. 0 => 'marti@ppsdfsd.pl',
  18. 1 => 'kowal@map.pl',
  19. ),
  20.  
  21. 'password' => Array
  22. (
  23. 0 => 'chauyec66',
  24. 1 => '456tre',
  25. ),
  26. 'Submit' => 'Zamawiam',
  27. );
  28. $destArray = array();
  29. unset($srcArray['Submit']);
  30. foreach($srcArray as $key => $val){
  31. foreach($val as $personId => $personValue){
  32. $destArray[$personId][$key] = $personValue;
  33. }
  34. }
  35. var_dump($destArray);
  36.  


wynik:

Kod
array(2) {
  [0]=>
  array(4) {
    ["name"]=>
    string(5) "Marta"
    ["nazwisko"]=>
    string(5) "Warta"
    ["email"]=>
    string(16) "marti@ppsdfsd.pl"
    ["password"]=>
    string(9) "chauyec66"
  }
  [1]=>
  array(4) {
    ["name"]=>
    string(3) "Jak"
    ["nazwisko"]=>
    string(8) "Kowalski"
    ["email"]=>
    string(12) "kowal@map.pl"
    ["password"]=>
    string(6) "456tre"
  }
}
Go to the top of the page
+Quote Post
DannyM
post
Post #3





Grupa: Zarejestrowani
Postów: 507
Pomógł: 2
Dołączył: 30.10.2003
Skąd: Poznań

Ostrzeżenie: (10%)
X----


  1. $srcArray = Array
  2. ($_POST);
  3. $destArray = array();
  4. unset($srcArray['Submit']);
  5. foreach($srcArray as $key => $val){
  6. foreach($val as $personId => $personValue){
  7. $destArray[$personId][$key] = $personValue;
  8. }
  9. }
  10.  
  11. var_dump($destArray);

i wynik

  1. array(5) {
  2. ["name"]=>
  3. array(1) {
  4. [0]=>
  5. array(2) {
  6. [0]=>
  7. string(5) "Marta"
  8. [1]=>
  9. string(3) "Jak"
  10. }
  11. }
  12. ["nazwisko"]=>
  13. array(1) {
  14. [0]=>
  15. array(2) {
  16. [0]=>
  17. string(5) "Warta"
  18. [1]=>
  19. string(8) "Kowalski"
  20. }
  21. }
  22. ["email"]=>
  23. array(1) {
  24. [0]=>
  25. array(2) {
  26. [0]=>
  27. string(16) "marti@ppsdfsd.pl"
  28. [1]=>
  29. string(12) "kowal@map.pl"
  30. }
  31. }
  32. ["password"]=>
  33. array(1) {
  34. [0]=>
  35. array(2) {
  36. [0]=>
  37. string(9) "chauyec66"
  38. [1]=>
  39. string(6) "456tre"
  40. }
  41. }
  42. ["Submit"]=>
  43. array(1) {
  44. [0]=>
  45. string(8) "Zamawiam"
  46. }
  47. }


Nie wiem czemu tak smiesznie

  1. foreach($_POST as $key => $val){

tak wyszlo ok
Dziekuje bardzo (IMG:style_emoticons/default/smile.gif)

Ten post edytował DannyM 17.12.2009, 16:55:48
Go to the top of the page
+Quote Post
piotrekkr
post
Post #4





Grupa: Zarejestrowani
Postów: 386
Pomógł: 25
Dołączył: 28.09.2005

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


$srcArray = Array($_POST); zamien na $srcArray = $_POST;
Go to the top of the page
+Quote Post
Largo
post
Post #5





Grupa: Zarejestrowani
Postów: 203
Pomógł: 6
Dołączył: 11.09.2005

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


Witaj,

Tak śmiesznie wyszło, ponieważ $_POST to też tablica... Więc konstrukcja $srcArray = Array( $_POST ); daję wynik z dodatkową tablicą dla globalnej $_POST. Zmień na $srcArray = $_POST; i powiedz czy zadziała.

@up - szybszy o parę sekund ^^

Pozdrawiam,
Largo

Ten post edytował Largo 17.12.2009, 17:06:10
Go to the top of the page
+Quote Post
DannyM
post
Post #6





Grupa: Zarejestrowani
Postów: 507
Pomógł: 2
Dołączył: 30.10.2003
Skąd: Poznań

Ostrzeżenie: (10%)
X----


O.k resumujac mam

  1. <table border="1" cellspacing="1" cellpadding="0">
  2. <tr>
  3. <td>Dane</td>
  4.  
  5. </tr>
  6. <?php
  7. $srcArray = $_POST;
  8. $destArray = array();
  9. unset($srcArray['Submit']);
  10. foreach($srcArray as $key => $val){
  11. foreach($val as $personId => $personValue){
  12. $destArray[$personId][$key] = '<tr> <td>'.$personValue.'</td> </tr>';
  13. }
  14. }
  15. var_dump($destArray);
  16.  
  17. </table>

efektem mam
  1. <table border="1" cellspacing="1" cellpadding="0">
  2. <tr>
  3. <td>Dane kursanta</td>
  4.  
  5. </tr>
  6. array(2) {
  7. [0]=>
  8. array(4) {
  9. ["name"]=>
  10. string(26) "<tr> <td>Daniel</td> </tr>"
  11. ["nazwisko"]=>
  12. string(25) "<tr> <td>Baniel</td> </tr>"
  13. ["email"]=>
  14. string(37) "<tr> <td>daniel@ppsdfsd.pl</td> </tr>"
  15. ["password"]=>
  16. string(25) "<tr> <td>dddd6</td> </tr>"
  17. }
  18. [1]=>
  19. array(4) {
  20. ["name"]=>
  21. string(25) "<tr> <td>Magda</td> </tr>"
  22. ["nazwisko"]=>
  23. string(24) "<tr> <td>Babra</td> </tr>"
  24. ["email"]=>
  25. string(34) "<tr> <td>mag@sdtgdf.pl</td> </tr>"
  26. ["password"]=>
  27. string(25) "<tr> <td>tttt4</td> </tr>"
  28. }
  29. }
  30.  

jak sie pozbyc tego poza tabela?

Ten post edytował DannyM 17.12.2009, 17:28:48
Go to the top of the page
+Quote Post
piotrekkr
post
Post #7





Grupa: Zarejestrowani
Postów: 386
Pomógł: 25
Dołączył: 28.09.2005

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


  1. <table border="1" cellspacing="1" cellpadding="0">
  2. <tr>
  3. <td>Imię</td>
  4. <td>Nazwisko</td>
  5. <td>E-mail</td>
  6. <td>Hasło</td>
  7. </tr>
  8. <?php
  9. $srcArray = $_POST;
  10. $destArray = array();
  11. unset($srcArray['Submit']);
  12. foreach($srcArray as $key => $val){
  13. foreach($val as $personId => $personValue){
  14. $destArray[$personId][$key] = $personValue;
  15. }
  16. }
  17. foreach($destArray as $person){
  18. echo '<tr><td>'.implode('</td><td>', $person).'</td></tr>';
  19. }
  20. </table>


Ten post edytował piotrekkr 17.12.2009, 17:35:30
Go to the top of the page
+Quote Post
DannyM
post
Post #8





Grupa: Zarejestrowani
Postów: 507
Pomógł: 2
Dołączył: 30.10.2003
Skąd: Poznań

Ostrzeżenie: (10%)
X----


No mistrzowsko (IMG:style_emoticons/default/winksmiley.jpg)
Dziekuje. Czegos sie nauczylem (IMG:style_emoticons/default/smile.gif)
Punkciki rozdane (IMG:style_emoticons/default/biggrin.gif)

Ten post edytował DannyM 17.12.2009, 17:39:23
Go to the top of the page
+Quote Post

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: 2.10.2025 - 18:14