Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class InfoTest {
- private $info_results;
- public function __construct() {
- $dbc = get_dbc();
- $info = $dbc->query ("SELECT info_id, info_title FROM text");
- if ($dbc->error) {
- printf("Error: %sn", $dbc->error);
- }
- while ($info_row = $info->fetch_array())
- {
- $info_results[]= $info_row;
- }
- $info->free();
- $this->info_results = $info_results;
- }
- public function setInfo() {
- $this->info_results = $info_results;
- }
- public function getInfo() {
- return $this->info_results;
- }
- public function __destruct() {
- }
- }
- ?>
- <?php
- $display = new InfoTest();
- foreach ($display->getInfo() as $info_row) {
- ?>
- <!-- html -->
- <?php echo $info_row['info_title']."</a><br />"; ?>
- <!-- html -->
- Sub-Info:
- <?php
- $dbc = get_dbc();
- $si_title = $dbc->query ("SELECT info_title FROM text WHERE info_id = ".$info_row['info_id']."");
- if ($dbc->error) {
- printf("Error: %sn", $dbc->error);
- }
- $num =$si_title->num_rows;
- $count = 0;
- while ($sub_info = $si_title->fetch_array())
- {
- $sub_info_title = $sub_info['info_title'];
- if ($count!=$num-1)
- {
- echo $sub_info_title." , ";
- $count++;
- }
- else echo $sub_info_title;
- }
- ?>
- <!-- html -->
- <?php } ?>
- <?php
- $dbc = get_dbc();
- $si_title = $dbc->query ("SELECT info_title FROM text WHERE info_id = ".$info_row['info_id']."");
- if ($dbc->error) {
- printf("Error: %sn", $dbc->error);
- }
- $num =$si_title->num_rows;
- $count = 0;
- while ($sub_info = $si_title->fetch_array())
- {
- $sub_info_title = $sub_info['info_title'];
- if ($count!=$num-1)
- {
- echo $sub_info_title." , ";
- $count++;
- }
- else echo $sub_info_title;
- }
- ?>
- public function getInfoTitles($info_id) {
- $titles = array();
- foreach ($this->info_results as $info_row) {
- if ($info_row['info_id'] == $info_id)
- $titles[] = $info_row['info_title'];
- }
- }
- return $titles;
- }
- echo implode(', ', $display->getInfoTitles($info_row['info_id']));
- class InfoTest {
- private $items;
- public function __construct() {
- $this->items = new Array();
- }
- private function queryItems($itemId){
- $dbc = get_dbc();
- $info = $dbc->query("SELECT info_id, info_title FROM text");
- if ($dbc->error) {
- printf("Error: %sn", $dbc->error);
- }
- while ($info_row = $info->fetch_array())
- {
- $item = new ItemInfo($info_row);
- $this->items[] = $item;
- }
- $info->free();
- }
- public function getItems($itemId){
- if (empty($this->items)){
- $this->queryItems($itemId);
- }
- return $this->items;
- }
- /* Other functions. */
- public function __destruct() {
- }
- }
- Class ItemInfo{
- private $id, $title;
- function __construct(Array $params){
- $this->id = $params['item_id'];
- $this->title = $params['item_title'];
- }
- function getTitle(){
- return $this->title;
- }
- function toString(){
- retirn "I'm item {$this->id}, my title is {$this->title}";
- }
- }
- $item_test = new ItemTest();
- $items = $item_test->getItems($item_id);
- $titles = array();
- foreach ($items as $item){
- //you may process your items in any way you need
- $titles[] = $item->getTitle();
- }
- echo implode(',', $titles);
Add Comment
Please, Sign In to add comment