Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Pobieranie tablicy $tblica[0][nazwa] $tablica[1][nazwa]
pawel06281990
post 26.01.2022, 10:30:09
Post #1





Grupa: Zarejestrowani
Postów: 281
Pomógł: 0
Dołączył: 10.01.2014

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


Witam,

Mam problem z pobraniem tablic format tablic jest taki

  1. Array ( [0] => Array ( [id] => 615c9da1938709beb0cc3126 [first_name] => Paweł [last_name] => D [phone_number] => zastrzezony numer [email] => adres e-mail klienta [gender] => male [city] => [country] => Poland [date_created] => 2021-10-05T20:46:57+02:00 [date_updated] => 2021-10-05T20:46:57+02:00 [description] => [groups] => Array ( [0] => Array ( [id] => 61583ac8938709beb0dd8c18 [name] => default [date_created] => 2021-10-02T12:56:08+02:00 [date_updated] => 2021-10-02T12:56:08+02:00 [description] => [created_by] => paweld1990@gmail.com [idx] => [contact_expire_after] => [contacts_count] => ) ) ) [1] => Array ( [id] => 615cb107938709beb0cc3213 [first_name] => Paweł [last_name] => D [phone_number] => top sekret [email] => adres e-mail klienta [gender] => male [city] => [country] => Poland [date_created] => 2021-10-05T22:09:43+02:00 [date_updated] => 2021-10-05T22:09:43+02:00 [description] => [groups] => Array ( [0] => Array ( [id] => 61583ac8938709beb0dd8c18 [name] => default [date_created] => 2021-10-02T12:56:08+02:00 [date_updated] => 2021-10-02T12:56:08+02:00 [description] => [created_by] => paweld1990@gmail.com [idx] => [contact_expire_after] => [contacts_count] => ) ) ) ) 2Array ( [0] => Array ( [id] => 615c9da1938709beb0cc3126 [first_name] => Paweł [last_name] => Danielewski [phone_number] => 48693877150 [email] => danielpaw1@wp.pl [gender] => male [city] => [country] => Poland [date_created] => 2021-10-05T20:46:57+02:00 [date_updated] => 2021-10-05T20:46:57+02:00 [description] => [groups] => Array ( [0] => Array ( [id] => 61583ac8938709beb0dd8c18 [name] => default [date_created] => 2021-10-02T12:56:08+02:00 [date_updated] => 2021-10-02T12:56:08+02:00 [description] => [created_by] => paweld1990@gmail.com [idx] => [contact_expire_after] => [contacts_count] => ) ) ) [1] => Array ( [id] => 615cb107938709beb0cc3213 [first_name] => Paweł [last_name] => Danielewski [phone_number] => 48547125654 [email] => danielpaw1@o2.pl [gender] => male [city] => [country] => Poland [date_created] => 2021-10-05T22:09:43+02:00 [date_updated] => 2021-10-05T22:09:43+02:00 [description] => [groups] => Array ( [0] => Array ( [id] => 61583ac8938709beb0dd8c18 [name] => default [date_created] => 2021-10-02T12:56:08+02:00 [date_updated] => 2021-10-02T12:56:08+02:00 [description] => [created_by] => adres email twórcy [idx] => [contact_expire_after] => [contacts_count] => ) ) ) )


I kiedy robię to tak

  1. for( $x = 0; $x < count($lista_pol); $x++ )
  2. foreach ( $lista_pol as $list ) {
  3.  
  4. print_r($list);
  5. echo"<tr>";
  6. echo"<td>".$list[$x]['first_name']." ".$list[$x]['last_name']."</td>";
  7. echo"<td>".$list[$x]['phone_number']."</td>";
  8. echo"<td>".$list[$x]['email']."</td>";
  9. echo"<td><a href='".POWIADOMIENIA_SMS_URL."?page=powiadomienia_sms_edit&id=".$list[$x]['id']."'><img src='".POWIADOMIENIA_SMS_PATH."/assets/images/edit.png' title='".__('Edytuj','powiadomienia_sms')."'> </a>|";
  10. echo"<a href='".POWIADOMIENIA_SMS_URL."?page=powiadomienia_sms_lista&action=kasuj&id=".$list[$x]['id']."' onclick=\"return confirm('".__('Czy chcesz usunąć kontak z bazy', 'powiadomienia_sms')."');\"><img src='".POWIADOMIENIA_SMS_PATH."/assets/images/delete.png' title='".__('Skasuj','powiadomienia_sms')."'> </a>";
  11. echo"</td>");
  12.  
  13. }



To mam 2 tabele puste i 2 tabele z danymi z tablic a ja chce, aby pobrać tablice zawartością klientów z bazy smsapi nie wiem w czym robię błąd.

Ten post edytował pawel06281990 26.01.2022, 10:31:08
Go to the top of the page
+Quote Post
trueblue
post 26.01.2022, 10:52:26
Post #2





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
Dołączył: 11.03.2014

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


  1. foreach ($lista_pol[$x] as $list ) {


i odwoływanie się do $list, a nie do $list[$x]

https://www.phptutorial.net/php-tutorial/ph...ensional-array/


--------------------
Go to the top of the page
+Quote Post
pawel06281990
post 26.01.2022, 11:39:40
Post #3





Grupa: Zarejestrowani
Postów: 281
Pomógł: 0
Dołączył: 10.01.2014

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


Cytat(trueblue @ 26.01.2022, 10:52:26 ) *
  1. foreach ($lista_pol[$x] as $list ) {


i odwoływanie się do $list, a nie do $list[$x]

https://www.phptutorial.net/php-tutorial/ph...ensional-array/



To mam taki błąd jak zastosowałem się tak jak ty

  1. Warning: Invalid argument supplied for foreach() in /home/twoj-host/web/test.twoj-host.eu/public_html/wp-content/plugins/powiadomienia_sms/admin/powiadomienia_sms_lista.php on line 83
  2.  
  3. Warning: Invalid argument supplied for foreach() in /home/twoj-host/web/test.twoj-host.eu/public_html/wp-content/plugins/powiadomienia_sms/admin/powiadomienia_sms_lista.php on line 83

Go to the top of the page
+Quote Post
nospor
post 26.01.2022, 11:50:42
Post #4





Grupa: Moderatorzy
Postów: 36 455
Pomógł: 6292
Dołączył: 27.12.2004




A czemu poprostu nie:

foreach ($lista_pol as $list ) {
// a tutaj $list['first_name']
}

i juz
Powód edycji: [nospor]:


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
pawel06281990
post 26.01.2022, 12:08:57
Post #5





Grupa: Zarejestrowani
Postów: 281
Pomógł: 0
Dołączył: 10.01.2014

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


Cytat(nospor @ 26.01.2022, 11:50:42 ) *
A czemu poprostu nie:

foreach ($lista_pol as $list ) {
// a tutaj $list['first_name']
}

i juz


Ponieważ nic mi nie pokazuje

ja sprawdzam to tym var_dump($list['first_name']); to mam komunikat null

Tak nie działa
  1. foreach ($lista_pol as $list) {
  2.  
  3. echo"<tr>";
  4. echo"<td>".$list['first_name']." ".$list['last_name']."</td>";
  5. echo"<td>".$list['phone_number']."</td>";
  6. echo"<td>".$list['email']."</td>";
  7. echo"<td><a href='".POWIADOMIENIA_SMS_URL."?page=powiadomienia_sms_edit&id=".$list['id']."'><img src='".POWIADOMIENIA_SMS_PATH."/assets/images/edit.png' title='".__('Edytuj','powiadomienia_sms')."'> </a>|";
  8. echo"<a href='".POWIADOMIENIA_SMS_URL."?page=powiadomienia_sms_lista&action=kasuj&id=".$list['id']."' onclick=\"return confirm('".__('Czy chcesz usunąć kontak z bazy', 'powiadomienia_sms')."');\"><img src='".POWIADOMIENIA_SMS_PATH."/assets/images/delete.png' title='".__('Skasuj','powiadomienia_sms')."'> </a>";
  9. echo"</td>";
  10.  
  11. }


Bo tablica ma $tablica[0]['first_name'] $tablica[1]['first_name'] itd
Go to the top of the page
+Quote Post
nospor
post 26.01.2022, 12:12:15
Post #6





Grupa: Moderatorzy
Postów: 36 455
Pomógł: 6292
Dołączył: 27.12.2004




sie zdecyduj, albo $lista_pol albo $tablica. Kurcze....

Skoro
tablica ma $tablica[0]['first_name'] $tablica[1]['first_name'] itd

to:

foreach ($tablica as $list ) {
// a tutaj $list['first_name']
}

i juz.


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
pawel06281990
post 26.01.2022, 12:21:13
Post #7





Grupa: Zarejestrowani
Postów: 281
Pomógł: 0
Dołączył: 10.01.2014

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


Cytat(nospor @ 26.01.2022, 12:12:15 ) *
sie zdecyduj, albo $lista_pol albo $tablica. Kurcze....

Skoro
tablica ma $tablica[0]['first_name'] $tablica[1]['first_name'] itd

to:

foreach ($tablica as $list ) {
// a tutaj $list['first_name']
}

i juz.



Ja tylko tak pisze bo tak sa pokazywane tuturiale a ja mam w pętli tak

  1. foreach ($lista_pol as $list) {
  2. echo"<tr>";
  3.  
  4. echo"<td>".$list['first_name']." ".$list['last_name']."</td>";
  5. echo"<td>".$list['phone_number']."</td>";
  6. echo"<td>".$list['email']."</td>";
  7. echo"<td><a href='".POWIADOMIENIA_SMS_URL."?page=powiadomienia_sms_edit&id=".$list['id']."'><img src='".POWIADOMIENIA_SMS_PATH."/assets/images/edit.png' title='".__('Edytuj','powiadomienia_sms')."'> </a>|";
  8. echo"<a href='".POWIADOMIENIA_SMS_URL."?page=powiadomienia_sms_lista&action=kasuj&id=".$list['id']."' onclick=\"return confirm('".__('Czy chcesz usunąć kontak z bazy', 'powiadomienia_sms')."');\"><img src='".POWIADOMIENIA_SMS_PATH."/assets/images/delete.png' title='".__('Skasuj','powiadomienia_sms')."'> </a>";
  9. echo"</td>";
  10.  
  11. }


i nic mi się nie pokazuje bo powinienem mieć tak

  1. $list[0]['first_name'] $list[1]['first_name'] itd


Na pierwszy mówiłem ze mi pokazuje 2 puste pola i dwa wyniki te co są w tablicy $lista_pol , a jak zrobić, żeby się pokazywały same wyniki.

Ten post edytował pawel06281990 26.01.2022, 12:24:06
Go to the top of the page
+Quote Post
nospor
post 26.01.2022, 12:27:24
Post #8





Grupa: Moderatorzy
Postów: 36 455
Pomógł: 6292
Dołączył: 27.12.2004




Pokaz jeszcze raz co zawiera GLOWNA tablica, bo to co tutaj piszesz nie ma w ogole sensu w stosunku do struktury ktora pokazales na poczatku


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
pawel06281990
post 26.01.2022, 12:30:26
Post #9





Grupa: Zarejestrowani
Postów: 281
Pomógł: 0
Dołączył: 10.01.2014

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


Cytat(nospor @ 26.01.2022, 12:27:24 ) *
Pokaz jeszcze raz co zawiera GLOWNA tablica, bo to co tutaj piszesz nie ma w ogole sensu w stosunku do struktury ktora pokazales na poczatku


Tak wygląda główna tablica

  1. array(2) { ["size"]=> int(2) ["collection"]=> array(2) { [0]=> array(12) { ["id"]=> string(24) "615c9da1938709beb0cc3126" ["first_name"]=> string(6) "Paweł" ["last_name"]=> string(11) "D" ["phone_number"]=> string(11) "486938****" ["email"]=> string(16) "******l" ["gender"]=> string(4) "male" ["city"]=> string(0) "" ["country"]=> string(6) "Poland" ["date_created"]=> string(25) "2021-10-05T20:46:57+02:00" ["date_updated"]=> string(25) "2021-10-05T20:46:57+02:00" ["description"]=> string(0) "" ["groups"]=> array(1) { [0]=> array(9) { ["id"]=> string(24) "61583ac8938709beb0dd8c18" ["name"]=> string(7) "default" ["date_created"]=> string(25) "2021-10-02T12:56:08+02:00" ["date_updated"]=> string(25) "2021-10-02T12:56:08+02:00" ["description"]=> string(0) "" ["created_by"]=> string(20) "paweld****" ["idx"]=> string(0) "" ["contact_expire_after"]=> NULL ["contacts_count"]=> NULL } } } [1]=> array(12) { ["id"]=> string(24) "615cb107938709beb0cc3213" ["first_name"]=> string(6) "Paweł" ["last_name"]=> string(11) "Da****" ["phone_number"]=> string(11) "485471***" ["email"]=> string(16) "danielpaw1*****" ["gender"]=> string(4) "male" ["city"]=> string(0) "" ["country"]=> string(6) "Poland" ["date_created"]=> string(25) "2021-10-05T22:09:43+02:00" ["date_updated"]=> string(25) "2021-10-05T22:09:43+02:00" ["description"]=> string(0) "" ["groups"]=> array(1) { [0]=> array(9) { ["id"]=> string(24) "61583ac8938709beb0dd8c18" ["name"]=> string(7) "default" ["date_created"]=> string(25) "2021-10-02T12:56:08+02:00" ["date_updated"]=> string(25) "2021-10-02T12:56:08+02:00" ["description"]=> string(0) "" ["created_by"]=> string(20) "paweld1990@gmail.com" ["idx"]=> string(0) "" ["contact_expire_after"]=> NULL ["contacts_count"]=> NULL } } } } }


Ten post edytował pawel06281990 26.01.2022, 12:31:32
Go to the top of the page
+Quote Post
nospor
post 26.01.2022, 12:40:28
Post #10





Grupa: Moderatorzy
Postów: 36 455
Pomógł: 6292
Dołączył: 27.12.2004




Nie mozna bylo tak od razu?

  1. foreach ($tablica['collection'] as $list ) {
  2. // a tutaj $list['first_name']
  3. }


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
pawel06281990
post 26.01.2022, 12:57:30
Post #11





Grupa: Zarejestrowani
Postów: 281
Pomógł: 0
Dołączył: 10.01.2014

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


Cytat(nospor @ 26.01.2022, 12:40:28 ) *
Nie mozna bylo tak od razu?

  1. foreach ($tablica['collection'] as $list ) {
  2. // a tutaj $list['first_name']
  3. }


No można było od razu.

I wielkie dzięki za pomoc

Ten post edytował pawel06281990 26.01.2022, 12:58:01
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 Wersja Lo-Fi Aktualny czas: 24.04.2024 - 15:20