_db = new pag_dBal($db_connection); $this->_page = $page; $this->_per_page = $per_page; $this->_page_var = $page_var; $test = str_replace('%p', $_GET[$page_var], $link_format); $test2 = 'http://test.com'.$_SERVER['REQUEST_URI']; $parts = parse_url($test2); $tmp = explode('&', $parts['query']); foreach($tmp as $tmp2) { $tmp3 = explode('=', $tmp2); $query[$tmp3[0]] = $tmp3[1]; } unset($query[$page_var]); if (count($query)) { unset($tmp); foreach ($query as $key => $value) { $tmp[] = "$key=$value"; } $str = implode('&', $tmp); if (strpos($link_format, '?') !== false) { $link_format = str_replace('?', '&', $link_format); $link_format = '?'.$str.$link_format; } } $this->_link_format = $link_format; } /* args sql: the sql statement to return all the rows for the entire query Returns a mysql result. Usage: $res = $obj->query('Select * From my_table Where this_col = 1'); while ($row = mysql_fetch_assoc($res)) { //write out your record display } */ function query($sql) { $sql = str_replace(';', '', $sql); $res = $this->_db->query($sql); $row_count = $this->_db->num_rows($res); $this->pages = ceil($row_count / $this->_per_page) - 1; $this->_row_count = $row_count; //reset the page to max page if page number is greater then the number of pages $this->_page = ($this->_page > $this->pages) ? $this->pages : $this->_page; //reset the page number to 0 if the pagenumber is negative $this->_page = ($this->_page < 0) ? 0 : $this->_page; //multiply page times per page and subtract 1 because start is 0 based $this->start = ($this->_per_page * $this->_page); //if page was 0 then start will be -1 so we change this to 0 $this->start = ($this->start < 0) ? 0 : $this->start; //add the limits $sql .= ' Limit '.$this->start.', '.$this->_per_page; //store the query $this->_query = $sql; //store the result $this->_res = $this->_db->query($sql); //return the result return $this->_res; } //return one row from the result function get_row() { return $this->_db->fetch_assoc($this->_res); } function get_records($text_class='') { $output = " Showing records: ". ((int)$this->start + 1); $last = ($this->_page * $this->_per_page) + $this->_per_page; $last = ($last > $this->_row_count) ? $this->_row_count : $last; $output .= ' Through '. $last . ' of '. $this->_row_count .''; return $output; } /* args hide: hide first prev if on first page next last on last page fl: show first and last prev text: Previous text link next_text: Next Text Link hence Next > link class: the css class for links text class: the css class for text Returns (string) First Previous 1 2 3 4 5 Next Last */ function get_fp_pn_nl($hide=false, $fl=true, $prev_text='Previous',$next_text='Next', $link_class='', $text_class='') { $output = $this->get_first_prev($hide, $fl, $prev_text, $link_class, $text_class). $this->get_page_numbers($link_class, $text_class). $this->get_next_last($hide, $fl, $next_text, $link_class, $text_class); return $output; } /* args link class: the css class for links text class: the css class for text fl: show first and last prev text: Previous text link next_text: Next Text Link hence Next > Returns (string) First Previous */ function get_first_prev($hide=false, $fl=true, $prev_text='Previous', $link_class='', $text_class='') { $this->_check_valid(); if ($this->_page != 0) { if ($fl) { $output .= "_get_number(0)."\" class=\"$link_class\">First "; } $output .= "_get_number($this->_page - 1) ."\" class=\"$link_class\">$prev_text "; } elseif (!$hide) { if ($fl) { $output .= "First "; } $output .= "$prev_text "; } return $output; } /* args base_uri: the url base to use for pagintation links link class: the css class for links text class: the css class for text Returns (string) Next Last */ function get_next_last($hide=false, $fl=true, $next_text='Next', $link_class='', $text_class='') { $this->_check_valid($base_uri); if ($this->_page != $this->pages) { //return links $output .= "_get_number($this->_page + 1) ."\" class=\"$link_class\">$next_text "; if ($fl) { $output .= "_get_number($this->pages) . "\" class=\"$link_class\">Last"; } } elseif (!$hide) { //return text $output .= "$next_text "; if ($fl) { $output .= ""; } } return $output; } /* args base_uri: the url base to use for pagintation links link class: the css class for links text class: the css class for text Returns (string) 1 2 3 4 5 6 7 8 9 10 */ function get_page_numbers($link_class='', $text_class='') { $this->_check_valid($base_uri); $output = ''; for ($x = 0; $x <= $this->pages; $x++) { if (($this->_page)!= $x) { //return links $output .= "_get_number($x) ."\" class=\"$link_class\">" . ($x+1) ." "; } else { //return text $output .= "". ($x + 1) ." "; } } return $output; } /* Returns (string) Prev | 2 | Next */ function short_with_num() { $this->_check_valid($base_uri); $output = $this->get_first_prev(true, false, 'Prev') . '| ' . ($this->_page + 1) .' | '. $this->get_next_last(true, false, 'Next').'
'; return $output; } /* Returns (string) Combobox with javascript form submittal */ function get_combo($combo_class='') { ?>
Goto page:
_check_valid($base_uri); $s1 = $this->_page - $before; $s1 = ($s < 1) ? 1 : $s1; $e1 = $this->_page + $after; $e1 = ($e1 > $this->pages) ? $this->pages : $e1; $l1 = ($e1 != $this->pages) ? $this->pages : 0; $tmp[] = ''; for ($x = 0; $x < $this->pages; $x++) { if ($this->_page != $x) { //return links $tmp[] = "".$x+1 ." "; } else { //return text $tmp[] = "".$x+1 ." "; } } return $output; } */ /* Returns (string) Returns a css stylable table with all the results in your query. */ function get_table($table_class='', $class_prefix='') { //lets not booger the orginal result returned by $obj->query $res = $this->_db->query($this->_query); $row = $this->_db->fetch_assoc($res); ?> $value) { ?> _db->query($this->_query); while ($row = $this->_db->fetch_assoc($res)) { ?> $value) { ?>
_res)) { echo 'Pagintation Error: No query pulled pagintation not possible.'; exit; //No need to do anything more kill the script no query was pulled } return $base_uri; } function _get_number($page) { $output = str_replace('%p', $page, $this->_link_format); return $output; } } ?> $val) { if($priority == 'tag') $attributes_data[$attr] = $val; else $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr' } } //See tag status and do the needed. if($type == "open") {//The starting of the tag '' $parent[$level-1] = &$current; if(!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag $current[$tag] = $result; if($attributes_data) $current[$tag. '_attr'] = $attributes_data; $repeated_tag_index[$tag.'_'.$level] = 1; $current = &$current[$tag]; } else { //There was another element with the same tag name if(isset($current[$tag][0])) {//If there is a 0th element it is already an array $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; $repeated_tag_index[$tag.'_'.$level]++; } else {//This section will make the value an array if multiple tags with the same name appear together $current[$tag] = array($current[$tag],$result);//This will combine the existing item and the new item together to make an array $repeated_tag_index[$tag.'_'.$level] = 2; if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well $current[$tag]['0_attr'] = $current[$tag.'_attr']; unset($current[$tag.'_attr']); } } $last_item_index = $repeated_tag_index[$tag.'_'.$level]-1; $current = &$current[$tag][$last_item_index]; } } elseif($type == "complete") { //Tags that ends in 1 line '' //See if the key is already taken. if(!isset($current[$tag])) { //New Key $current[$tag] = $result; $repeated_tag_index[$tag.'_'.$level] = 1; if($priority == 'tag' and $attributes_data) $current[$tag. '_attr'] = $attributes_data; } else { //If taken, put all things inside a list(array) if(isset($current[$tag][0]) and is_array($current[$tag])) {//If it is already an array... // ...push the new element into that array. $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; if($priority == 'tag' and $get_attributes and $attributes_data) { $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data; } $repeated_tag_index[$tag.'_'.$level]++; } else { //If it is not an array... $current[$tag] = array($current[$tag],$result); //...Make it an array using using the existing value and the new value $repeated_tag_index[$tag.'_'.$level] = 1; if($priority == 'tag' and $get_attributes) { if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well $current[$tag]['0_attr'] = $current[$tag.'_attr']; unset($current[$tag.'_attr']); } if($attributes_data) { $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data; } } $repeated_tag_index[$tag.'_'.$level]++; //0 and 1 index is already taken } } } elseif($type == 'close') { //End of tag '' $current = &$parent[$level-1]; } } return($xml_array); } ?>