View Full Version : Como fazer isto?


khaluh
03-01-2008, 12:32
Boas

Neste momento, no meu site tenho isto:

http://img442.imageshack.us/img442/299/oquetenhowl0.th.jpg (http://img442.imageshack.us/my.php?image=oquetenhowl0.jpg)

E gostava de saber como posso alterar para:

http://img442.imageshack.us/img442/1583/oquepretendoly4.th.jpg (http://img442.imageshack.us/my.php?image=oquepretendoly4.jpg)

Edit: A linguagem é PHP.


Podem-me ajudar?

Armadillo
03-01-2008, 12:35
linguagem?

khaluh
03-01-2008, 12:40
linguagem?

Desculpem, é em PHP.

Obs: Já editei a thread inicial

Armadillo
03-01-2008, 12:46
so vendo como está o teu codigo é que poderemos ajudar.
Mas podes ser mais explicito? Queres limitar/truncar o n.º de paginas a 6 e por um 'seguinte'? Ou fazer a paginação ('pag. 2 de 6')?

khaluh
03-01-2008, 12:51
so vendo como está o teu codigo é que poderemos ajudar.
Mas podes ser mais explicito? Queres limitar/truncar o n.º de paginas a 6 e por um 'seguinte'? Ou fazer a paginação ('pag. 2 de 6')?

O que pretendo fazer é limitar a 10 ou seja, que apareça do 1 ao 10, depois do 11 ao 20.

A parte de aparecer o 2 de 6 tb é interessante, mas secundária

Vou colocar o codigo:

function getPageNo() {
$str="";
$str=$str."<table width='200' border='0'><tr>";
$str=$str."<td width='30%' align='left' valign='top'>";
if($this->getPage()>1) {
$str=$str."<a href='".$_SERVER['PHP_SELF']."?page=".($this->getPage()-1).$this->getParameter()."' class='".$this->getStyle()."'>Anterior</a>&nbsp;";
}
for($i=1;$i<=$this->getNoOfPages();$i++) {
if($i==$this->getPage()) {
$str=$str."<span class='".$this->getActiveStyle()."'>".$i."&nbsp;</span>";
}
else {
$str=$str."<a href='".$_SERVER['PHP_SELF']."?page=".$i.$this->getParameter()."' class='".$this->getStyle()."'>".$i."</a>&nbsp;";
}
}
if($this->getPage()<$this->getNoOfPages()) {
$str=$str."<a href='".$_SERVER['PHP_SELF']."?page=".($this->getPage()+1).$this->getParameter()."' class='".$this->getStyle()."'>Seguinte</a>";
}
$str=$str."</td>";
$str=$str."<td align='right' valign='top' class='".$this->getStyle()."'>";
$str=$str."<form name='frmPage' action='".$_SERVER['PHP_SELF']."' method='get'>";
$str=$str."Página&nbsp;<input type='text' name='page' size='3' class='".$this->getStyle()."'>&nbsp;";
$param=split("[& =]",$this->getParameter());
for($i=2;$i<=count($param);$i=$i+2) {
$str=$str."<input type='hidden' name='".$param[$i-1]."' value='".$param[$i]."'>";
}
$str=$str."<input type='submit' name='btnGo' value='Ok' class='".$this->getButtonStyle()."'>";
$str=$str."</form>";
$str=$str."</td>";
$str=$str."</tr></table>";
print $str;
}

Armadillo
03-01-2008, 13:02
Nao sei se bastará fazer esta modificação, mas esperimenta e diz-me como ficou

function getPageNo() {
$str="";
$str=$str."<table width='200' border='0'><tr>";
$str=$str."<td width='30%' align='left' valign='top'>";
if($this->getPage()>1) {
$str=$str."<a href='".$_SERVER['PHP_SELF']."?page=".($this->getPage()-1).$this->getParameter()."' class='".$this->getStyle()."'>Anterior</a>&nbsp;";
}

//modificado


for($i=$this->getPage();$i<=($this->getPage())+10;$i++) {
if($i==$this->getPage()) {
$str=$str."<span class='".$this->getActiveStyle()."'>".$i."&nbsp;</span>";
}
else {
$str=$str."<a href='".$_SERVER['PHP_SELF']."?page=".$i.$this->getParameter()."' class='".$this->getStyle()."'>".$i."</a>&nbsp;";
}
}


//fim modificado



if($this->getPage()<$this->getNoOfPages()) {
$str=$str."<a href='".$_SERVER['PHP_SELF']."?page=".($this->getPage()+1).$this->getParameter()."' class='".$this->getStyle()."'>Seguinte</a>";
}




$str=$str."</td>";
$str=$str."<td align='right' valign='top' class='".$this->getStyle()."'>";
$str=$str."<form name='frmPage' action='".$_SERVER['PHP_SELF']."' method='get'>";
$str=$str."Página&nbsp;<input type='text' name='page' size='3' class='".$this->getStyle()."'>&nbsp;";
$param=split("[& =]",$this->getParameter());
for($i=2;$i<=count($param);$i=$i+2) {
$str=$str."<input type='hidden' name='".$param[$i-1]."' value='".$param[$i]."'>";
}
$str=$str."<input type='submit' name='btnGo' value='Ok' class='".$this->getButtonStyle()."'>";
$str=$str."</form>";
$str=$str."</td>";
$str=$str."</tr></table>";
print $str;
}


so modifique as vars do ciclo for.

khaluh
03-01-2008, 13:16
Nao sei se bastará fazer esta modificação, mas esperimenta e diz-me como ficou



//modificado


for($i=$this->getPage();$i<=($this->getPage())+10;$i++) {
if($i==$this->getPage()) {
$str=$str."<span class='".$this->getActiveStyle()."'>".$i."&nbsp;</span>";
}
else {
$str=$str."<a href='".$_SERVER['PHP_SELF']."?page=".$i.$this->getParameter()."' class='".$this->getStyle()."'>".$i."</a>&nbsp;";
}
}


//fim modificado

so modifique as vars do ciclo for.

Já faz o que pretendo, terei é de alterar depois as intruções Anterior e Seguinte, pois senão torna-se complicado regressar, por exemplo, da pagina 20 a 1, sem ser pela caixa de pesquisa.

Qual a melhor maneira de o fazer?

Armadillo
03-01-2008, 13:19
deves colocar um link para a 1ª e a ultima pagina do genero: <Anterior 1 .. 15 16 17 18 19 20 21 22 23 24 25 .. 83 Proxima>

khaluh
03-01-2008, 13:34
deves colocar um link para a 1ª e a ultima pagina do genero: <Anterior 1 .. 15 16 17 18 19 20 21 22 23 24 25 .. 83 Proxima>

Obrigado ;)

khaluh
03-01-2008, 13:58
deves colocar um link para a 1ª e a ultima pagina do genero: <Anterior 1 .. 15 16 17 18 19 20 21 22 23 24 25 .. 83 Proxima>

Bem, após fazer isso, surgiu a seguinte dúvida:
Neste momento, tenho 34 páginas, mas quando chego à pagina 33, ele continua a mostrar mais além da 34, vai até a 43 (para perfazer as 10 páginas de pesquisa, apontando todas para a 34).

O que pretendo é que nao apareçam as páginas em excesso...

anjo2
03-01-2008, 14:49
//modificado


for($i=$this->getPage();$i<=($this->getPage())+10 && $i<=$this->getNoOfPages();$i++) {
if($i==$this->getPage()) {
$str=$str."<span class='".$this->getActiveStyle()."'>".$i."&nbsp;</span>";
}
else {
$str=$str."<a href='".$_SERVER['PHP_SELF']."?page=".$i.$this->getParameter()."' class='".$this->getStyle()."'>".$i."</a>&nbsp;";
}
}

nfn
03-01-2008, 19:07
Eu costumo usar uma classe para o efeito -> http://www.bradyvercher.com/php-pagination-class.html.
Existem mais em www.phpclasses.org.

naoliveira
04-01-2008, 23:48
eu costumo usar esta função feita por mim

/* =====================================
* - - makes the html for nav links - -
*
* $page_num -> actual page
* $rows_page -> how many rows to show per page
* $total_page -> how many pages there are for the navigation
* $offset -> at wich row it starts the actual page
* $page_link -> the page link for navigation, including all querystring variables
* $show_links -> how many link to show before and after the actual page
* $pesquisar -> the search words, if the page is being viewed throw a search
* this criteria should pass among all pages like page number
*
* ================================================== =======*/
function nav_links ($page_num,$rows_page,$total_page,$offset,$page_li nk,$show_links,$pesquisar=''){
// print the link to access each page
$nav = '';
$total_show_links = 2 * $show_links;

// make a link navigation only
// if there are more than 1 page to show
if ($total_page > 1){
// criteria for a search
if ($pesquisar != '')
$pesquisar .= "&pesquisar=$pesquisar";


// shows link for 1st,previous,next,last, and for
// some pages before and some pages after the actual page
// shows 9 page links
$pages_before= $page_num - $show_links;
$pages_after = $page_num + $show_links;
// 1st page should be at least 1
if ($pages_before<1){
// $pages_after = $pages_after - $pages_before +1; // to continue showing all links
$pages_before = 1;
}
$pages_after=$pages_before + $total_show_links ;
// last page should be <= total pages
if ($pages_after > $total_page){
$pages_after=$total_page;
}

// shows 1st page link
if ($page_num>$show_links){
$nav = " <a href=\"{$page_link}1$pesquisar\">[Primeira]</a>";
}
else
$nav='[Primeira]';

// shows previous page link
if($page_num > 1){
$previous_page = $page_num -1;
$nav .= " <a href=\"{$page_link}$previous_page$pesquisar\">[<]</a>";
}
else
$nav .= ' [<]';

// make links for pages
for($page_actual = $pages_before; $page_actual <= $pages_after; $page_actual++)
{
if ($page_actual == $page_num)
{
$nav .= " $page_actual "; // no need to create a link to current page
}
else
{
$nav .= " <a href=\"{$page_link}$page_actual$pesquisar\">[$page_actual]</a>";
}
}

// shows next page link
if($page_num < $total_page){
$next_page = $page_num +1;
$nav .= " <a href=\"{$page_link}$next_page$pesquisar\">[>]</a>";
}
else{
$nav .=' [>]';
}

// shows last page link
if ($page_num < $total_page - $show_links)
$nav .= " <a href=\"{$page_link}$total_page$pesquisar\">[Última]</a>";
else
$nav .= ' [Última]';
}
return $nav;
}


para chamar esta função com todas as opções faço assim


// navigation variables
$page_num=1; // page where we are
$rows_total=0; // total rows
$rows_page=20; // how many rows per page
$total_page=0; // $rows_total / $rows_page
$offset = 0; // wich row to start the page
$show_links=2; // how many links to show before and after actual page
$nav='';

// check wich page we are, if not set it's 1st page
if (isset($_GET['page_num']))
$page_num=$_GET['page_num'];

$offset = ($page_num - 1) * $rows_page;

// get total rows
$query="SELECT id FROM actions";
$result = mysql_query ($query);
$rows_total=mysql_num_rows($result);

// get total pages
$total_page=ceil($rows_total / $rows_page);

$page_link = "$php_self?page=teste&page_num=";
$nav= nav_links($page_num,$rows_page,$total_page,$offset ,$page_link,$show_links);