Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [HTML][MySQL][PHP]Jak zbudować tabelkę z arraya w arrayu ?
phpamator
post
Post #1





Grupa: Zarejestrowani
Postów: 328
Pomógł: 3
Dołączył: 10.07.2016
Skąd: UK-raine

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


Hejka rebiata,

Napotkałem problem z którym ni jak nie wiem jak sobie poradzić (IMG:style_emoticons/default/wink.gif)
Właściwie to wiem ale coś mi nie idzie.
Otóż jako wynik wybierania danych z bazy otrzymuję coś takiego:
  1. array(1) { [0]=> array(13) { ["sku"]=> string(9) "bsr4739cl" ["entity_id"]=> string(4) "7391" ["name"]=> string(35) "ABC Design Takeoff Stroller - Coral" ["manufacturer_id"]=> string(4) "1662" ["manufacturer_name"]=> string(10) "ABC Design" ["price"]=> string(8) "249.9900" ["special_price"]=> string(8) "200.0000" ["final_price"]=> string(8) "200.0000" ["image"]=> string(20) "/5/1/51076-501_1.jpg" ["url_path"]=> string(38) "abc-design-takeoff-stroller-coral.html" ["percent_approved"]=> NULL ["vote_count"]=> NULL ["rating"]=> string(6) "310.00" } } array(1) { [0]=> array(13) { ["sku"]=> string(9) "bsr4739cr" ["entity_id"]=> string(4) "7392" ["name"]=> string(39) "ABC Design Takeoff Stroller - Cranberry" ["manufacturer_id"]=> string(4) "1662" ["manufacturer_name"]=> string(10) "ABC Design" ["price"]=> string(8) "249.9900" ["special_price"]=> string(8) "200.0000" ["final_price"]=> string(8) "200.0000" ["image"]=> string(20) "/5/1/51076-502_1.jpg" ["url_path"]=> string(42) "abc-design-takeoff-stroller-cranberry.html" ["percent_approved"]=> NULL ["vote_count"]=> NULL ["rating"]=> string(4) "3.00" } } array(1) { [0]=> array(13) { ["sku"]=> string(9) "bsr4743cr" ["entity_id"]=> string(4) "7396" ["name"]=> string(38) "ABC Design Avito Pushchair - Cranberry" ["manufacturer_id"]=> string(4) "1662" ["manufacturer_name"]=> string(10) "ABC Design" ["price"]=> string(8) "249.9900" ["special_price"]=> string(8) "200.0000" ["final_price"]=> string(8) "200.0000" ["image"]=> string(22) "/5/1/51075-502_1_1.jpg" ["url_path"]=> string(41) "abc-design-avito-pushchair-cranberry.html" ["percent_approved"]=> NULL ["vote_count"]=> NULL ["rating"]=> string(6) "372.00" } } array(1) { [0]=> array(13) { ["sku"]=> string(9) "bsr4743lm" ["entity_id"]=> string(4) "7397" ["name"]=> string(33) "ABC Design Avito Pushchair - Lime" ["manufacturer_id"]=> string(4) "1662" ["manufacturer_name"]=> string(10) "ABC Design" ["price"]=> string(8) "249.9900" ["special_price"]=> string(8) "200.0000" ["final_price"]=> string(8) "200.0000" ["image"]=> string(20) "/5/1/51075-503_1.jpg" ["url_path"]=> string(36) "abc-design-avito-pushchair-lime.html" ["percent_approved"]=> NULL ["vote_count"]=> NULL ["rating"]=> string(7) "-385.00" } } array(1) { [0]=> array(13) { ["sku"]=> string(10) "bsr4758bcr" ["entity_id"]=> string(4) "7403" ["name"]=> string(51) "ABC Design Cobra 2 in 1 Pushchair - Black/Cranberry" ["manufacturer_id"]=> string(4) "1662" ["manufacturer_name"]=> string(10) "ABC Design" ["price"]=> string(8) "459.9900" ["special_price"]=> string(8) "420.0000" ["final_price"]=> string(8) "420.0000" ["image"]=> string(23) "/3/1/31171-530502_1.jpg" ["url_path"]=> string(54) "abc-design-cobra-2-in-1-pushchair-black-cranberry.html" ["percent_approved"]=> NULL ["vote_count"]=> NULL ["rating"]=> string(6) "166.00" } }
Co to jest ?
Otóż jest to tablica a w niej kolejnych 5 tablic. Mając taki miszmasz do dyspozycji chciałbym bez o ile to mozliwe specjalnych kombinacji wyciągać dane w kolejności:
index1 - ["sku"] ..... kolejno ze wszystkich tablic,
index2 - ["entity_id"] ..... kolejno ze wszystkich tablic,
itd ... itd ...
nie wiem jednak jak to zrobić.
Próbowałem tak:
Pewnie zwróciliście uwagę na to, że wszystkie tablice to array(1), no własnie, w tej chwili wpadło mi to w oko. Chyba muszę dodać jakiś ekstra licznik bo jak miałbym rozróżnić która ma być czytana ?
Dobrze kombinuję ?
A może poprostu sam proces ich generowania powinienem wziąć pod lupę ?
  1. <?php
  2. $output =
  3. array(1) {[0]=> array(13) ( ["sku"]=> string(9) "bsr4739cl" ["entity_id"]=> string(4) "7391" ["name"]=> string(35) "ABC Design Takeoff Stroller - Coral" ["manufacturer_id"]=> string(4) "1662" ["manufacturer_name"]=> string(10) "ABC Design" ["price"]=> string(8) "249.9900" ["special_price"]=> string(8) "200.0000" ["final_price"]=> string(8) "200.0000" ["image"]=> string(20) "/5/1/51076-501_1.jpg" ["url_path"]=> string(38) "abc-design-takeoff-stroller-coral.html" ["percent_approved"]=> NULL ["vote_count"]=> NULL ["rating"]=> string(6) "310.00" }
  4. }
  5.  
  6. array(1) {[0]=> array(13) { ["sku"]=> string(9) "bsr4739cr" ["entity_id"]=> string(4) "7392" ["name"]=> string(39) "ABC Design Takeoff Stroller - Cranberry" ["manufacturer_id"]=> string(4) "1662" ["manufacturer_name"]=> string(10) "ABC Design" ["price"]=> string(8) "249.9900" ["special_price"]=> string(8) "200.0000" ["final_price"]=> string(8) "200.0000" ["image"]=> string(20) "/5/1/51076-502_1.jpg" ["url_path"]=> string(42) "abc-design-takeoff-stroller-cranberry.html" ["percent_approved"]=> NULL ["vote_count"]=> NULL ["rating"]=> string(4) "3.00" }
  7. }
  8.  
  9. array(1) { [0]=> array(13) { ["sku"]=> string(9) "bsr4739lm" ["entity_id"]=> string(4) "7393" ["name"]=> string(34) "ABC Design Takeoff Stroller - Lime" ["manufacturer_id"]=> string(4) "1662" ["manufacturer_name"]=> string(10) "ABC Design" ["price"]=> string(8) "249.9900" ["special_price"]=> string(8) "200.0000" ["final_price"]=> string(8) "200.0000" ["image"]=> string(20) "/5/1/51076-503_1.jpg" ["url_path"]=> string(37) "abc-design-takeoff-stroller-lime.html" ["percent_approved"]=> NULL ["vote_count"]=> NULL ["rating"]=> string(6) "596.00" }
  10. }
  11.  
  12. array(1) {[0]=> array(13) { ["sku"]=> string(9) "bsr4743cl" ["entity_id"]=> string(4) "7395" ["name"]=> string(34) "ABC Design Avito Pushchair - Coral" ["manufacturer_id"]=> string(4) "1662" ["manufacturer_name"]=> string(10) "ABC Design" ["price"]=> string(8) "249.9900" ["special_price"]=> string(8) "200.0000" ["final_price"]=> string(8) "200.0000" ["image"]=> string(20) "/5/1/51075-501_1.jpg" ["url_path"]=> string(37) "abc-design-avito-pushchair-coral.html" ["percent_approved"]=> NULL ["vote_count"]=> NULL ["rating"]=> string(6) "236.00" }
  13. }
  14.  
  15. array(1) { [0]=> array(13) { ["sku"]=> string(9) "bsr4743cr" ["entity_id"]=> string(4) "7396" ["name"]=> string(38) "ABC Design Avito Pushchair - Cranberry" ["manufacturer_id"]=> string(4) "1662" ["manufacturer_name"]=> string(10) "ABC Design" ["price"]=> string(8) "249.9900" ["special_price"]=> string(8) "200.0000" ["final_price"]=> string(8) "200.0000" ["image"]=> string(22) "/5/1/51075-502_1_1.jpg" ["url_path"]=> string(41) "abc-design-avito-pushchair-cranberry.html" ["percent_approved"]=> NULL ["vote_count"]=> NULL ["rating"]=> string(6) "372.00" }
  16. };
  17.  
  18. $c=1;
  19.  
  20. ?>
  21. <table border="1">
  22. <tr>
  23. <th></th>
  24. <?php
  25. foreach ($output as $key => $html)
  26. {
  27. echo "<th>SKU ".$key."</th>";
  28. }
  29. ?>
  30. </tr>
  31. <tr>
  32. <td>SKU</td>
  33. <?php
  34. foreach ($output as $key => $html)
  35. {
  36. echo "<td>".$html['sku']."</td>";
  37. }
  38. ?>
  39. </tr>
  40. </table>
  41.  


Podpowiedzcie ..... proszę (IMG:style_emoticons/default/wink.gif)

Ten post edytował PHPRexio 11.07.2016, 09:23:17
Go to the top of the page
+Quote Post

Posty w temacie
- PHPRexio   [HTML][MySQL][PHP]Jak zbudować tabelkę z arraya w arrayu ?   10.07.2016, 23:02:40
- - mlawnik   Przeformatuj ten output bo aż oczy bolą   11.07.2016, 09:26:57
- - PHPRexio   Ok, zrobię to ... ale jak ? Tu pojawia się proble...   11.07.2016, 09:41:44
- - Pyton_000   echo '<pre>'; var_dump($tabliac...   11.07.2016, 10:16:10
- - IAmBoskiM   Ja sobie zrobiłem taką funkcję: [PHP] pobierz, pla...   11.07.2016, 11:24:42
- - PHPRexio   Tablice dostaje w skutek wyciagniecia danych z baz...   12.07.2016, 10:00:54
- - mlawnik   Potrzebujesz funkcji foreach. Przelatujesz po tych...   12.07.2016, 11:07:35
- - trueblue   Cytat(PHPRexio @ 12.07.2016, 11:00:54...   12.07.2016, 11:14:24
- - mlawnik   Rozwiązanie @trueblue jest lepsze od mojego. (Będz...   12.07.2016, 11:17:40
- - PHPRexio   Dzięki panowie, W wyniku działania otrzymałem: [PH...   12.07.2016, 11:39:46
- - trueblue   Przecież wynik już jest tabelką. Jeśli chcesz to z...   12.07.2016, 11:43:57
- - PHPRexio   Miałem na myśli wrzucić do tabelki <html> P...   12.07.2016, 11:46:23
- - trueblue   To jaki sens jest sklejać id i sku? Przecież teraz...   12.07.2016, 11:49:34
- - PHPRexio   Nie nie, czekaj, wkradło się jakies drobne nieporo...   12.07.2016, 11:54:23
- - trueblue   Jeśli chcesz prezentować produkty w kolumnach/pion...   12.07.2016, 12:45:58
- - PHPRexio   Zabiłeś mi ćwieka ...... Ni potrafię sobie z tym p...   12.07.2016, 13:29:18
- - trueblue   Nie widzę między tymi dwiema tabelami różnicy. Jed...   12.07.2016, 13:33:12
- - PHPRexio   Sugerujesz, że mogę zbudować tabelę uzywając pierw...   12.07.2016, 14:07:13


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: 25.08.2025 - 02:43