How do I put a .php pageing script on my website?

0

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.

    
asked by anonymous 05.08.2018 / 01:47

1 answer

1

First of all let's define a few things, phpMyAdmin is your interface for managing the database, where you store the records that will be retrieved at some point, such as texts and so on. Your .php file should be stored in your hosting, along with the other .html files and etc ... It will communicate with your database to retrieve the information to be paginated.  In order for your pagination to work, you will need to embed php on your html page, using include or require, read more about them:

Include: link

Require: link

Example with include:

include 'diretorio1/diretorio2/paginacao.php';

But from what I understand, only this information will not solve your problem, since other knowledge needs to be acquired in order for that paging to work and be implemented in a more appropriate way. I believe that in your trajectory in php learning, you will see that some actions should be taken regarding this paging file, an example would be the extraction of your database connection to another file.  I do not know what the purpose of your project is, but in many cases it pays to use a CMS (Content Manager System) such as Joomla or WordPress, things like paging, it would be something to not worry about, BUT that does not mean you will not get that study the operation.

    
05.08.2018 / 03:26