Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Efekt rekurencji bez rekurencji, tabelka tabelek.
sanneo
post
Post #1





Grupa: Zarejestrowani
Postów: 25
Pomógł: 0
Dołączył: 15.01.2008
Skąd: Warszawa

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


Witajcie.

Próbuję rozwiązać swój problem dotyczący efektu rekurencji bez rekurencji, a to z powodu ograniczeń PHP co do rekurencji do 100 poziomu.

Moim celem jest wygenerowanie tabelki tabelek, które składają się na strukturę jak w linku poniżej, bez ograniczeń co do zagłębienia, jedyne ograniczenie, które akceptuję, to limit pamięci RAM komputera (HTML w przeglądarce).

Efekt jaki chcę uzyskać (bez zagłębienia):

http://sanneo.nazwa.pl/_tmp/tabela1.html

Drugi poziom zagłębienia i kolejne:

http://sanneo.nazwa.pl/_tmp/tabela2.html
http://sanneo.nazwa.pl/_tmp/tabela3.html
http://sanneo.nazwa.pl/_tmp/tabela4.html

Próbuję już od wielu godzin, ale bez rezultatu.

Proszę o pomoc.

Pozdrawiam.
Mariusz (sanneo)

Ten post edytował sanneo 11.01.2012, 22:18:02
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
sanneo
post
Post #2





Grupa: Zarejestrowani
Postów: 25
Pomógł: 0
Dołączył: 15.01.2008
Skąd: Warszawa

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


Witam.

Dzięki za pomoc.

Dla zainteresowanych zamieszczam cały kod poniżej.

Jeszcze pewnie będę to jakoś optymalizował, ale efekt jest taki jak potrzebuję (IMG:style_emoticons/default/smile.gif)

Pozdrawiam.
Mariusz (sanneo)

  1. <style type="text/css">
  2. table {
  3. border-collapse: collapse;
  4. }
  5. td {
  6. padding: 5px 10px;
  7. border: solid 1px red;
  8. }
  9. </style>
  10. <?php
  11. class tableOfTables
  12. {
  13. private $_depthLevel;
  14.  
  15. public function __construct($depthLevel = 1){
  16. $this->_depthLevel = $depthLevel;
  17. }
  18. public function generateHTML($HTMLBlockCode){
  19. $HTMLBlocksCodeArray = array(
  20. 'a' => array(0, 1, 2, 7, 4, 3),
  21. 'b' => array(0, 1, 2, 7, 4, 3, 8, 4, 5, 1, 3, 9, 4, 5, 6),
  22. 'c' => array(4, 5, 1, 3),
  23. 'd' => array(4, 5, 6),
  24. );
  25. $HTMLElementsArray = array(
  26. '<table>', // 0
  27. '<tr>', // 1
  28. '<td rowspan="2">', // 2
  29. '<td>', // 3
  30. '</td>', // 4
  31. '</tr>', // 5
  32. '</table>', // 6
  33. '1', // 7
  34. '2', // 8
  35. '3', // 9
  36. );
  37. $out = '';
  38. $HTMLBlocksCode = $HTMLBlocksCodeArray[$HTMLBlockCode];
  39. foreach($HTMLBlocksCode as $HTMLElementIndex){
  40. $out .= $HTMLElementsArray[$HTMLElementIndex];
  41. }
  42. return $out;
  43. }
  44. public function createDepthSeparator(){
  45. for($a = 0; $a < $this->_depthLevel; $a++){
  46. $c = $b . $a . $b;
  47. $b = $c;
  48. }
  49. return $c;
  50. }
  51. public function createTable($depthLevel = 1){
  52.  
  53. $this->_depthLevel = $depthLevel;
  54. $depthSeparator = $this->createDepthSeparator();
  55.  
  56. $tableContentsHTMLBlocks = pow(2, $this->_depthLevel);
  57.  
  58. // Create all opens
  59. echo str_repeat($this->generateHTML('a'), $this->_depthLevel);
  60.  
  61. // Create table contents
  62. for($a = 0; $a < $tableContentsHTMLBlocks; $a++){
  63. echo $this->generateHTML('b');
  64. if($a < ($tableContentsHTMLBlocks-1)){
  65. echo str_repeat($this->generateHTML('d'), substr($depthSeparator, $a, 1));
  66. echo $this->generateHTML('c');
  67. echo str_repeat($this->generateHTML('a'), substr($depthSeparator, $a, 1));
  68. }
  69. }
  70. // Create all closes
  71. echo str_repeat($this->generateHTML('d'), $this->_depthLevel);
  72. }
  73. }
  74. $table = new tableOfTables();
  75. $table->createTable(5);


Ten post edytował sanneo 14.01.2012, 21:17:08
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: 28.12.2025 - 23:53