Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Złączenie tablic przed danym elementem
Forum PHP.pl > Forum > Przedszkole
potreb
Witam, mam problem z jedną rzeczą a dokładnie:
  1. function tree()
  2. {
  3. $sql = $this->pdo->query("SELECT * FROM `plugins` ORDER BY `ptitle`");
  4. $tree[] = array('section_id' => 2, 'section_parent_id' => '1', 'section_name' => 'Użytkownicy', 'section_module' => '#', 'section_plugin' => '', 'depth' => 1);
  5. $tree[] = array('section_id' => 3, 'section_parent_id' => '1', 'section_name' => 'System', 'section_module' => '#', 'section_plugin' => '', 'depth' => 1);
  6. $tree[] = array('section_id' => 4, 'section_parent_id' => '1', 'section_name' => 'Zawartość', 'section_module' => '#', 'section_plugin' => '', 'depth' => 1);
  7.  
  8. $i = 4;
  9. while($r = $sql->fetch(PDO::FETCH_OBJ))
  10. {
  11. $tree[] = array('section_id' => $i, 'section_parent_id' => $r->prights+1, 'section_name' => $r->ptitle, 'section_module' => $r->plink, 'section_plugin' => $r->pinstall, 'depth' => 2);
  12. $i++;
  13. }
  14. return $tree;
  15. }


Wyświetla mi tablicę w takiej postaci:
  1. Array
  2. (
  3. [0] => Array
  4. (
  5. [section_id] => 2
  6. [section_parent_id] => 1
  7. [section_name] => Użytkownicy
  8. [section_module] => #
  9. [section_plugin] =>
  10. [depth] => 1
  11. )
  12.  
  13. [1] => Array
  14. (
  15. [section_id] => 3
  16. [section_parent_id] => 1
  17. [section_name] => System
  18. [section_module] => #
  19. [section_plugin] =>
  20. [depth] => 1
  21. )
  22.  
  23. [2] => Array
  24. (
  25. [section_id] => 4
  26. [section_parent_id] => 1
  27. [section_name] => Zawartość
  28. [section_module] => #
  29. [section_plugin] =>
  30. [depth] => 1
  31. )
  32.  
  33. [3] => Array
  34. (
  35. [section_id] => 4
  36. [section_parent_id] => 2
  37. [section_name] => Administratorzy
  38. [section_module] => administrators
  39. [section_plugin] => 0
  40. [depth] => 2
  41. )
  42.  
  43. [4] => Array
  44. (
  45. [section_id] => 5
  46. [section_parent_id] => 3
  47. [section_name] => Backup
  48. [section_module] => backup
  49. [section_plugin] => 0
  50. [depth] => 2
  51. )
  52.  
  53. [5] => Array
  54. (
  55. [section_id] => 6
  56. [section_parent_id] => 4
  57. [section_name] => FAQ
  58. [section_module] => faq
  59. [section_plugin] => 1
  60. [depth] => 2
  61. )
  62.  
  63. [6] => Array
  64. (
  65. [section_id] => 7
  66. [section_parent_id] => 4
  67. [section_name] => Formularz kontaktowy
  68. [section_module] => contact
  69. [section_plugin] => 1
  70. [depth] => 2
  71. )
  72. )


Pierwsze trzy elementy powinny być wstawione przed tablicę, która zawiera wartość section_parent_id równą section_id. Niestety nie wiem jaką funkcję zastosować, aby połączyć tablicę, tak aby te 3 elementy znalazły się przed pierwszym elementem swojej podkategorii.

Mógłbym to zrobić innym sposobem, jednak jestem ciekaw czy jest jakaś funkcja, która pozwoli to zrobić szybciej
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.