Guest User

Untitled

a guest
Jul 21st, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. <?php
  2. class InfoTest {
  3.  
  4. private $info_results;
  5.  
  6. public function __construct() {
  7. $dbc = get_dbc();
  8. $info = $dbc->query ("SELECT info_id, info_title FROM text");
  9. if ($dbc->error) {
  10. printf("Error: %sn", $dbc->error);
  11. }
  12. while ($info_row = $info->fetch_array())
  13. {
  14. $info_results[]= $info_row;
  15. }
  16. $info->free();
  17. $this->info_results = $info_results;
  18. }
  19.  
  20.  
  21. public function setInfo() {
  22. $this->info_results = $info_results;
  23. }
  24.  
  25. public function getInfo() {
  26. return $this->info_results;
  27. }
  28.  
  29. public function __destruct() {
  30. }
  31.  
  32. }
  33.  
  34. ?>
  35. <?php
  36. $display = new InfoTest();
  37. foreach ($display->getInfo() as $info_row) {
  38. ?>
  39. <!-- html -->
  40. <?php echo $info_row['info_title']."</a><br />"; ?>
  41. <!-- html -->
  42. Sub-Info:
  43. <?php
  44. $dbc = get_dbc();
  45. $si_title = $dbc->query ("SELECT info_title FROM text WHERE info_id = ".$info_row['info_id']."");
  46. if ($dbc->error) {
  47. printf("Error: %sn", $dbc->error);
  48. }
  49. $num =$si_title->num_rows;
  50. $count = 0;
  51. while ($sub_info = $si_title->fetch_array())
  52. {
  53. $sub_info_title = $sub_info['info_title'];
  54. if ($count!=$num-1)
  55. {
  56. echo $sub_info_title." , ";
  57. $count++;
  58. }
  59. else echo $sub_info_title;
  60. }
  61. ?>
  62. <!-- html -->
  63. <?php } ?>
  64.  
  65. <?php
  66. $dbc = get_dbc();
  67. $si_title = $dbc->query ("SELECT info_title FROM text WHERE info_id = ".$info_row['info_id']."");
  68. if ($dbc->error) {
  69. printf("Error: %sn", $dbc->error);
  70. }
  71. $num =$si_title->num_rows;
  72. $count = 0;
  73. while ($sub_info = $si_title->fetch_array())
  74. {
  75. $sub_info_title = $sub_info['info_title'];
  76. if ($count!=$num-1)
  77. {
  78. echo $sub_info_title." , ";
  79. $count++;
  80. }
  81. else echo $sub_info_title;
  82. }
  83. ?>
  84.  
  85. public function getInfoTitles($info_id) {
  86. $titles = array();
  87. foreach ($this->info_results as $info_row) {
  88. if ($info_row['info_id'] == $info_id)
  89. $titles[] = $info_row['info_title'];
  90. }
  91. }
  92. return $titles;
  93. }
  94.  
  95. echo implode(', ', $display->getInfoTitles($info_row['info_id']));
  96.  
  97. class InfoTest {
  98.  
  99. private $items;
  100.  
  101. public function __construct() {
  102. $this->items = new Array();
  103. }
  104.  
  105. private function queryItems($itemId){
  106. $dbc = get_dbc();
  107. $info = $dbc->query("SELECT info_id, info_title FROM text");
  108. if ($dbc->error) {
  109. printf("Error: %sn", $dbc->error);
  110. }
  111. while ($info_row = $info->fetch_array())
  112. {
  113. $item = new ItemInfo($info_row);
  114. $this->items[] = $item;
  115. }
  116. $info->free();
  117. }
  118.  
  119. public function getItems($itemId){
  120. if (empty($this->items)){
  121. $this->queryItems($itemId);
  122. }
  123. return $this->items;
  124. }
  125.  
  126. /* Other functions. */
  127. public function __destruct() {
  128. }
  129. }
  130.  
  131. Class ItemInfo{
  132. private $id, $title;
  133. function __construct(Array $params){
  134. $this->id = $params['item_id'];
  135. $this->title = $params['item_title'];
  136. }
  137.  
  138. function getTitle(){
  139. return $this->title;
  140. }
  141.  
  142. function toString(){
  143. retirn "I'm item {$this->id}, my title is {$this->title}";
  144. }
  145. }
  146.  
  147. $item_test = new ItemTest();
  148. $items = $item_test->getItems($item_id);
  149. $titles = array();
  150. foreach ($items as $item){
  151. //you may process your items in any way you need
  152. $titles[] = $item->getTitle();
  153. }
  154. echo implode(',', $titles);
Add Comment
Please, Sign In to add comment