0
I’ve already built a website, but I’m having trouble with the paging system. I don’t know how to handle php, I found some videos on youtube and got a script of php pagination. Now I need to put this script inside my site.
I think for this I need to link the . php file inside my . html type file when the guy uses the 'link' command in html. But I don’t know how to do it.
This is the php pagination script:
The part of database connection is in the first 15 lines of the script I pasted.
<?php
$servername = "Localhost";
$username = "id6683339_unknn";
$password = "****";
// Create connection
$conn = mysql_connect("mysql#.000webhost.com","id6683339_unknn","****") or die(mysql_error());
// Check connection
if ($conn->connect_error) {
`insira o código aqui`die("Connection failed: " . $conn->connect_error);}
echo "Connected successfully";
?>
<?php
$maxlinks = 4;
$pagina = (isset($_GET['pagina'])) ? (int)$_GET['pagina'] : 1;
$maximo = 12;
$inicio = (($maximo * $pagina) - $maximo);
$selecao = $pdo->prepare("SELECT * FROM `posts` ORDER BY id DESC LIMIT $inicio, $maximo");
$selecao->execute();
while($posts = $selecao->fetchObject()):
?>
<li><?php echo utf8_encode($posts->titulo);?></li>
<?php endwhile;?>
<?php
$seleciona_2 = $pdp->prepare("SELECT * FROM `posts`");
$seleciona_2->execute();
$total = $seleciona_2->rowCount();
$total_paginas = ceil($total/$maximo);
if($total > $maximo){
echo '<a href="?pagina=1">Primeira pagina</a>';
for($i = $pagina - $maxlinks; $i <= $pagina -1; $i++){
if($i >= 1){
echo '<a href="?pagina='.$i.'">'.$i.'</a>';
}
}
echo '<span>'.$pagina.'</span>';
for($i = $pagina +1; $i <= $pagina + $maxlinks; $i++){
if($i <= $total_paginas){
echo '<a href="?pagina='.$i.'">'.$i.'</a>';
}
}
echo '<a href="?pagina='.$total_paginas.'">Ultima pagina</a>';
}
?>
I don’t know if the paging script is right, but the question is I don’t know how to put it on my website. I hosted my website on 000webhost.com, I found that to mess with file. php needs to use phpmyadmin, 000webhost uses phpmyadmin database but I don’t know how to work it, I started learning programming a couple of weeks ago.
In phpmyadmin there are 3 folders, I don’t know if you need to put the file. php inside a special folder.
It would be easier to use apache server, but at the moment it is not working on my pc, I need to format it.
places it in the place where it will be in html
include "nome_do_arquivo_de_paginacao.php;"
– Wees Smith
Your HTML file must have the php extension to work what @Weessmith said. Type
home.html
has to behome.php
– Andrei Coelho
Thanks for the comment @Andreicoelho
– Wees Smith
Before doing this I suggest learning php, and at least have a notion of database, make a functional pagination is something a little advanced for those who started programming 2 weeks
– Costamilam
@You’re absolutely right, and I’m gonna do just that.
– jim
Friend, if you need to do php/html paging, do not complicate your life by making the entire pagination in hand, I would advise, first of all, to do what @Guilhermecostamilam said, study php/database. Another thing, this pagination can be used datagrid. Much simpler, nicer and more efficient https://www.pontikis.net/labs/bs_grid/demo/
– gabrielfalieri
@gabrielfalieri datagrid is certainly simpler, beautiful is opinion, but it is not more efficient, imagine that the paging is 1000 lines from the bank, having to load all this for at the end the user go at most to page two, can even be considered efficient in relation to the agility in the development, but not in the performance of the system
– Costamilam
Dude, have you seen how datagrid works? That it sends the request with an order by 10 to 19, 20 to 29 and so on.. never the 1000 bank lines at once
– gabrielfalieri
I haven’t seen this, but anyway you have to make the changes in php, validate these
LIMIT
andOFFSET
not to have SQL Injection. At the end of more work. Obs:ORDER BY
does not make pagination– Costamilam