start inteligente formulario ejemplo criterios busqueda buscar buscador avanzado php tabs page-numbering

inteligente - Problemas con la pestaña actual y los números de página en php



session start php (1)

allí he creado un programa con un botón de tabulación y un número de página. todas las funciones casi funcionan correctamente hasta que noté un pequeño problema. como todos sabemos, las pestañas siempre resaltan la pestaña actual en la que se encuentra. Digamos si sus pestañas son letras AZ y un # que significa inicio o página principal, y su # es la página actual, y las páginas principales consisten en la lista de empleados registrados en su base de datos. dado que tengo el número de página (Siguiente y Anterior), he limitado el número o la cantidad de nombres / información de los empleados por 5, indicando que solo 5 registros deberían aparecer en la pantalla.

nota: mi código está funcionando, pero 1 problema se deslizó. cada vez que hago clic en el siguiente botón para ver la otra lista de empleados, la pestaña # no está resaltada, en donde se supone que debe estar resaltada ya que está en la misma página. ¿Alguien sabe qué causa esto y cómo solucionarlo? Lo siento si no está tan claro ya que es tan difícil de explicar.

ejemplo: (IMAGINAR ESTO COMO LA VENTANA) digamos que el límite es = 2

**#** A B C D E F G H I J K L M N O P Q R S T U V W X Y Z //this is the tabs button, notice the # is highlighted employee_id : employee_name : employee_age 1 chel 26 2 brandon 35 **PREV** **NEXT** //this is the page number

cuando intento hacer clic para ver al siguiente empleado en la página principal, la página se ve así:

# A B C D E F G H I J K L M N O P Q R S T U V W X Y Z //notice the # is NOT highlighted after you click next employee_id : employee_name : employee_age 3 charlie 28 4 sasha 24 **PREV** **NEXT**

Espero haber aclarado mi problema en esta simple ilustración. Espero que alguien pueda ayudarme. Gracias

//this is my tabs codes <?php function toc_menu($current){ $return =''<ol id="toc"> ''."/n"; $return .= ($current=='''') ? ''<li class="current"><a href="index.php?namelist=%"><span>#</span></a></li>''."/n" : ''<li><a href="index.php"><span>#</span></a></li>''."/n"; foreach(range(''a'',''z'') as $link){ $return .= ($current==$link) ? ''<li class="current"><a href="index.php?namelist=''.$link.''"><span>''.strtoupper($link).''</span></a></li>''."/n" : ''<li><a href="index.php?namelist=''.$link.''"><span>''.strtoupper($link).''</span></a></li>''."/n"; } $return .="</ol>/n"; return $return; } if(isset($_GET[''namelist''])) { $current=$_GET[''namelist'']; } else {$current=''''; } //echo where you want the menu if(isset($_GET[''namelist''])) { echo toc_menu(strtolower($_GET[''namelist''])); $tocmenu = toc_menu(strtolower($_GET[''namelist''])); } else { echo toc_menu(strtolower('''')); } //or hold it in a variable to display later on ?> //and this is my page_number codes: <?php if ($offset>=1) { // bypass PREV link if offset is 0 $prevoffset=$offset-$limit; print "<a href=/"".htmlentities($_SERVER[''PHP_SELF''])."?offset=$prevoffset&searchfile=$search&namelist=$listname/"/>Prev</a> &nbsp;"; } echo ''</td> <td colspan ="5" height ="20" align="right"''; // check to see if last page if (!($offset+$limit > $total)) { // not last page so give NEXT link if ($offset == 1) { $newoffset=$offset+($limit-1); } else { $newoffset=$offset+$limit; } print "<a href=/"".htmlentities($_SERVER[''PHP_SELF''])."?offset=$newoffset&searchfile=$search&namelist=$listname/">Next</a> &nbsp;"; } ?>

TENGA EN CUENTA: Mi lista de nombres de variables se utiliza para la variable AZ que es el archivo de búsqueda para mi botón de búsqueda MisaChan


Después de luchar con esta larga pieza de código, lo único que veo que puede estar causando un problema es $listname

si listname no es una letra, su código no funcionará.

esto es lo que sugerí, ya que su código no está ordenado alfabéticamente, debería considerar usar números en su lugar. AZ tendrá de 1 a 10 o 1 to total pages , tiene mucho más sentido,

aquí hay una clase que utilizo para manejar la paginación fácilmente

class Pagination { public $current_page; public $per_page; public $page_count; public function __construct($page=1,$per_page= 15, $total_count=0) { $this->current_page = $page; $this->per_page = $per_page; $this->total_count = $total_count; } public function offset() { return ($this->current_page -1)* $this->per_page; } public function total_pages () { return ceil($this->total_count/ $this->per_page); } public function previous_page () { return $this->current_page -1; } public function next_page () { return $this->current_page +1; } public function has_previous_page () { return $this->previous_page() >= 1? true : false; } public function has_next_page () { return $this->next_page() <= $this->total_pages()? true : false; } // edit this section to suit your needs public function format_output ($link,$query) { if ($this->total_pages() > 1) { $output = "<div id=/"pagination/"><p>"; $output .= ($this->has_previous_page())? ("<a href=/"/$link/".$this->previous_page()."/{$query}/" >Previous</a>"): ""; $c = $this->current_page; $t = $this->total_pages(); for ( $i = 1; $i <= $t; $i++ ) { if ($this->current_page == $i) { $output .= " <a class=/"active/" href=/"#/" >{$i}</a> "; }else { $output .= " <a href=/"/$link/{$i}/{$query}/" >{$i}</a> "; //$output .= " <a href=/"$link?q={$query}&page={$i}/" >{$i}</a> "; } } $output .= (($t ==$this->total_pages())?"":'' ... ''); $output .= ($this->has_next_page())? ("<a href=/"/$link/".$this->next_page()."/{$query}/" >Next</a>"): ""; $output .= "</p></div>"; }else { $output = "<div id=/"pagination/"><p>Displaying all results.</p></div>"; } return $output; } } ?>

y así es como lo uso.

// your listname in numbers $currentPage = isset($_GET[''currentPage''])? $_GET[''currentPage'']: 1; // page number $limit =2; // you decided to limit 2 per page $total = 10; // the total result available in all pages $pagination = new Pagination($currentPage, $limit,$total); // if you need the the value of how many to offset for the current page $offset = $pagination->offset(); // example page 6 will return 12 // and to display the pagination simply echo this echo $pagination->format_output(htmlentities($_SERVER[''PHP_SELF'']),''other values u want to pass'');

Esto creará automáticamente el botón anterior y siguiente para usted

Espero que esto te ayude a resolver tu problema