I've already built a website, but I'm having trouble with the paging system. I do not know how to mess with php, I found some videos on youtube and got a paging script in php. 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 do not know how.
This is the php script:
The database connection part 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 do not know if the paging script is right, but the question is I do not know how to put it on my website. I hosted my website on 000webhost.com, I found that to move with .php file you need to use phpmyadmin, 000webhost uses the phpmyadmin database but I do not know how to move it, I started to learn programming about 2 weeks ago
In phpmyadmin there are 3 folders, I do not know if you need to put the .php file inside a specific folder.
It would be easier for me to use the apache server, but at the moment it is not working on my pc, I need to format it.