paging does not load the next records

Asked

Viewed 113 times

0

Hello, after running a search, it delivers the specified amount in the code, so far so good... now enter my problem, I’m using url friendly and even if the form send with "...? page=1" guess it does not assign the value to $string,
errors presented:

page link ("...?page=2" and so on) does not load the page or the next records; if you change page and press the back of the browser, do not load the page (neither with or without the search items) after performing the search the items remain even if I go to another page and come back(by clicking the directional to the page where lists the records) it displays the search items + the items that are listed by default on the page

Form code: (pg = site link)

<form class="form-inline" name="search" id="search_form" method="post" action="<?php echo pg.'/videos?pagina=1'; ?>">
    <div class="input-group">
        <input type="text" class="form-control" placeholder="Search" name="pesquisar" id="pesquisar" value="">
        <span class="input-group-btn">
            <button type="submit" class="btn btn-primary"><i class="fa fa-search" aria-hidden="true"></i></button>
        </span>
    </div>
</form>

Index:

<!-- Conteudo -->
<?php 
$url = (isset($_GET['url'])) ? $_GET['url']:'';
$explode = explode('/',$url);


$paginas = array('home','categories','videos','video');
if(isset($explode[0])&& $explode[0] == ''){
    include "home.php";
}elseif($explode[0] != ''){
    if(isset($explode[0]) && in_array($explode[0], $paginas)){
        include $explode[0].".php";
    }else{
        include "home.php";
    }
}
?>

Page that receives the records:

<?php 
    $url = (isset($_GET['url'])) ? $_GET['url']:'';
    $explode = explode('/',$url);
    $categoria = $explode[1];

    $query_vid = "SELECT * FROM videos ORDER BY id DESC";
    $resultado = mysqli_query($conectar, $query_vid);


    $query = "SELECT * FROM videos WHERE categoria_id='$categoria' or categoria_id2='$categoria' or categoria_id3='$categoria' or categoria_id4='$categoria' or categoria_id5='$categoria' ORDER BY id DESC";
    $resultado_vid = mysqli_query($conectar, $query);
?>
<?php
        if($_SERVER['REQUEST_METHOD']=='POST'){
            $pesquisar = $_POST['pesquisar'];
            $pagina = 1;
            $_SESSION['pesquisar'] = $pesquisar;

            listar($pesquisar, $pagina, $conectar);

        }elseif((isset($_SESSION['pesquisar']))){
            $pagina = (isset($_GET['pagina'])) ? $_GET['pagina'] : 1;
            listar($_SESSION['pesquisar'], $pagina, $conectar);
        }
        function listar($pesquisar, $pagina, $conectar){
            //Selcionar todos os registros da tabela

    $query_pesqu = "SELECT * FROM videos WHERE nome LIKE '%$pesquisar%' or desc_vid LIKE '%$pesquisar%' or tags LIKE '%$pesquisar%' ORDER BY id DESC";
    $resultado_pesqu = mysqli_query($conectar, $query_pesqu);

    //Contar o total de registros
    $total_pesq = mysqli_num_rows($resultado_pesqu);

    //Setar quantidade de registros por pagina
    $qnt_result_pg = 3;

    //Calcular o inicio da visualização
    $inicio = ($qnt_result_pg*$pagina)-$qnt_result_pg;

    //Selecionar os registros a serem apresentado na página
    $query_pesq = "SELECT * FROM videos WHERE nome LIKE '%$pesquisar%' or desc_vid LIKE '%$pesquisar%' or tags LIKE '%$pesquisar%' ORDER BY id DESC LIMIT $inicio, $qnt_result_pg";             
    $resultado_pesq = mysqli_query($conectar, $query_pesq);
?>
<?php if ($pesquisar != ''){?>

while ($linhas_pesq = mysqli_fetch_assoc($resultado_pesq)){
$imagem = pg.'/media/videos/'.$linhas_pesq['imagem'];
$vid_nome = $linhas_pesq['nome'];
$vid_nome = str_replace(" ","-",$vid_nome);
$link_vid = pg.'/video/'.$linhas_pesq['id'].'/'.$vid_nome;      
?>
<div id="<?php echo $linhas_pesq['id'] ?>" class="col-sm-4 m-b-15" title="<?php echo $linhas_pesq['nome'] ?>">
<div class="well well-sm">
<div class="thumb-overlay">
<a href="<?php echo $link_vid; ?>">
<div class="thumb-overlay">
<img src="<?php echo $imagem; ?>" id="<?php echo $linhas_pesq['id'].".jpg" ?>" class="img-responsive ">
    <div class="hd-text-icon">HD</div>                                  
    <div class="duration"><?php echo $linhas_pesq['tempo'] ?></div>                                     
</div></a>
<div class="actions"></div></div>
<a href="<?php echo $link_vid; ?>">
<div class="video-title title-truncate"><?php echo $linhas_pesq['nome'] ?>  </div></a>
<div class="video-views pull-left">viewr</div>
<div class="video-rating pull-right no-rating">
    <i class="fa fa-heart video-rating-heart no-rating active"></i> <b>-</b>
</div><div class="clearfix"></div>                                      
</div></div>
<?php }   
            //************* INICIO PAGINAÇÂO **************/
            //Qunatidade de paginas
            $quantidade_pg = ceil($total_pesq / $qnt_result_pg);

            //Limite de link antes e depois 
            $MaxLinks = 2;

            echo "<br>";

            echo "<a href='videos?pagina=1'>Primeira</a> ";

            for($iPag = $pagina - $MaxLinks; $iPag <= $pagina - 1; $iPag++){
                if($iPag >= 1){
                    echo "<a href='videos?pagina=$iPag'>$iPag</a> ";
                }
            }

            echo " $pagina ";

            for($dPag = $pagina + 1; $dPag <= $pagina + $MaxLinks; $dPag++){
                if($dPag <= $quantidade_pg){
                    echo "<a href='videos?pagina=$dPag'>$dPag</a> ";
                }
            }

            echo "<a href='videos?pagina=$quantidade_pg'>Última</a>";
        }}
    ?>          

<?php if ($pesquisar == ''){?>
<?php if ($categoria == ''){
while($linhas = mysqli_fetch_assoc($resultado)){ 
$imagem = pg.'/media/videos/'.$linhas['imagem'];
$vid_nome = $linhas['nome'];
$vid_nome = str_replace(" ","-",$vid_nome);
$link_vid = pg.'/video/'.$linhas['id'].'/'.$vid_nome;

?>

<div id="<?php echo $linhas['id'] ?>" class="col-sm-4 m-b-15" title="<?php echo $linhas['nome'] ?>">
<div class="well well-sm">
<div class="thumb-overlay">
<a href="<?php echo $link_vid; ?>">
<div class="thumb-overlay">
<img src="<?php echo $imagem; ?>" id="<?php echo $linhas['id'].".jpg" ?>" class="img-responsive ">
    <div class="hd-text-icon">HD</div>                                  
    <div class="duration"><?php echo $linhas['tempo'] ?></div>                                      
</div></a>
<div class="actions"></div></div>
<a href="<?php echo $link_vid; ?>">
<div class="video-title title-truncate"><?php echo $linhas['nome'] ?></div> </a>
<div class="video-views pull-left">viewr</div>
<div class="video-rating pull-right no-rating">
    <i class="fa fa-heart video-rating-heart no-rating active"></i> <b>-</b>
</div><div class="clearfix"></div>                                      
</div></div>
<?php }} ?>

<?php 
if ($categoria != ''){
while($linhas_vid = mysqli_fetch_assoc($resultado_vid)){
$imagem = pg.'/media/videos/'.$linhas_vid['imagem'];
$vid_nome = $linhas_vid['nome'];
$vid_nome = str_replace(" ","-",$vid_nome);
$link_vid = pg.'/video/'.$linhas_vid['id'].'/'.$vid_nome;   
?>

<div id="<?php echo $linhas_vid['id'] ?>" class="col-sm-4 m-b-15" title="<?php echo $linhas_vid['nome'] ?>">
<div class="well well-sm">
<div class="thumb-overlay">
<a href="<?php echo $link_vid; ?>">
<div class="thumb-overlay">
<img src="<?php echo $imagem; ?>" id="<?php echo $linhas_vid['id'].".jpg" ?>" class="img-responsive ">
    <div class="hd-text-icon">HD</div>                                  
    <div class="duration"><?php echo $linhas_vid['tempo'] ?></div>                                      
</div></a>
<div class="actions"></div></div>
<a href="<?php echo $link_vid; ?>">
<div class="video-title title-truncate"><?php echo $linhas_vid['nome'] ?>   </div></a>
<div class="video-views pull-left">viewr</div>
<div class="video-rating pull-right no-rating">
    <i class="fa fa-heart video-rating-heart no-rating active"></i> <b>-</b>
</div><div class="clearfix"></div>                                      
</div></div>

<?php }} ?>                         
<?php } ?>
  • I know the code is very badly done, but in my defense I’m still understanding how php works, Thank you

  • can you explain this /videos? page=1 not missing an extension? example .... /videos.ext? page=1

  • Edited with missing information

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.