column)<1) { $this->error[] = 'You have not set any column names'; } if(empty($this->error)) { //add table id if set if(!empty($this->id)) { $add_id = ' id="'.$this->id.'"'; } //add defaults if not set if(empty($this->css_class)) { $this->css_class = 'table'; } if(empty($this->cellspacing)) { $this->cellspacing = '2'; } if(empty($this->cellpadding)) { $this->cellpadding = '2'; } if(empty($this->limit)) { $this->limit = '10'; } $this->table .= ''; //create $this->table .= $this->create_table_head(); //create if(empty($this->error)) { $this->table .= $this->create_table_body(); } $this->table .= ""; //create page numbers if(empty($this->error)) { $this->table .= $this->create_page_numbers(); } } //return completed table if(empty($this->error)) { return $this->table; } else { return show_message($this->error, 'There was an error building your table'); } } /* private functions ------------------------------------------------- */ //create private function create_table_head() { $return_html = ""; $return_html .= ""; $return_html .= ""; foreach($this->column as $key=>$value) { $return_html .= "" . $value . ""; } $return_html .= ""; $return_html .= ""; return $return_html; } //create private function create_table_body() { //check what page we are on $this->check_page_number(); $return_html = ""; $counter = 0; foreach($this->row as $row) { //alternate row colours if($counter++ % 2 == 0) { $class = "odd"; } else { $class = "even"; } //only display results within our limit if($counter >= $this->limit_from and $counter <= $this->limit_to) { $return_html .= ""; foreach($row as $key=>$value) { $return_html .= "".$value.""; } $return_html .= ""; } } return $return_html; } //check what page to show private function check_page_number() { if(!isset($_GET['pg'])){ $this->current_page = 1; } else { $this->current_page = $_GET['pg']; } $this->limit_from = (($this->current_page * $this->limit) - $this->limit); $this->limit_to = $this->limit_from + $this->limit; return TRUE; } //create page numbers private function create_page_numbers() { $return_html = ""; $total_rows = count($this->row); $total_pages = ceil($total_rows / $this->limit); if($total_pages>1) { $return_html .= "
"; //link to first page if($this->current_page != 1) { $return_html .= "<<"; } if($this->current_page > 1) { $prev = ($this->current_page - 1); // Previous Link $return_html .= "<"; } for($i = 1; $i <= $total_pages; $i++) { //only show 5 pages +/- of current page $limit = 5; if($i > ($this->current_page-$limit) and $i < ($this->current_page+$limit)) { if(($this->current_page) == $i) { $return_html .= "$i "; } else { $return_html .="$i "; } } } if($this->current_page < $total_pages) { $next = ($this->current_page + 1); // Next Link $return_html .=">"; } //link to last page if($this->current_page != $total_pages) { $return_html .= ">>"; } $return_html .= "
"; } return $return_html; } } ?>