0
I am trying to adapt the relative links to absolutes in my pagination script. However, whenever I try to go forward or back a page, the link is as follows:
http://localhost/textos?pag=2?pag=3
Script:
<?php
$url = $_SERVER['SERVER_NAME'];
$urlEndereco = $_SERVER ['REQUEST_URI'];
?>
<table border="1">
<tr>
<?php
if($pag!=1){
echo "<td><a href='http://".$url.$urlEndereco."?pag=".($pag-1)."'> Página Anterior</a></td>";
}
if($contador<=$maximo){
echo "<td>Existe apenas uma única página</td>";
}
else{
for($i=1;$i<=$paginas;$i++){
if($pag==$i){
echo "<td style='background: red'><a href='http://".$url.$urlEndereco."?pag=".$i."'> ".$i."</a></td>";
}else{
echo "<td><a href='http://".$url.$urlEndereco."?pag=".$i."'> ".$i."</a></td>";
}
}
}
if($pag!=$paginas){
echo "<td><a href='http://".$url.$urlEndereco."?pag=".($pag+1)."'> Próxima Página</a></td>";
}
?>
</tr>
</table>
However, if I use the code below, it works normally. But it turns out that I will use paging with a include on several pages to clean the code, having an easier control.
echo "<td><a href='textos?pag=".($pag+1)."'> Próxima Página</a></td>";
I also realized that the $urlEndereco that’s causing this, since it does the $_SERVER['REQUEST_URI'];
, always return the end of the url: http://localhost/textos?pag=2?pag=3
Related: PHP script paging
– rray
Not necessarily, his problem is as a URL, which has nothing to do directly with the subject matter dealt with in this other pagination post.
– Inkeliz
Yes, but anyway it was of great help. Thank you!
– Cobra