I am creating a search system and I need to create a pagination I thought I would use $_SESSION
but I noticed that it would give error follow below the code that I have developed so far
Search:
<?php
if(isset($_GET['PG'])){
if(isset($_SESSION['pg'])){
$id=$numpg-$_SESSION['pg'];
}else{
$_GET['PG']=0;
}
}else{
$_GET['PG']=0;
}
if(is_numeric($_GET['PG'])){
?>
<div class="corpo container">
<?php
$i=0;
?>
<div class="row">
<?php
$ps=$_GET['PS'];
$sql="SELECT id FROM indexes WHERE (modo!=4 and nome LIKE '%$ps%') ORDER BY id DESC";
$exe=mysqli_query($link,$sql);
$numrow=mysqli_num_rows($exe);
if($_GET['PG']==0){
$sql="SELECT nome,foto,vew,tkm,modo,id FROM indexes WHERE (modo!=4 and nome LIKE '%$ps%') ORDER BY id DESC LIMIT 12";
}else{
$sql="SELECT nome,foto,vew,tkm,modo,id FROM indexes WHERE (modo!=4 and nome LIKE '%$ps%') and (id <= $id) ORDER BY id DESC LIMIT 12";
}
$exe=mysqli_query($link,$sql);
//echo e($numrow);
while($row=MYSQLI_FETCH_ARRAY($exe)){
$nome=$row['nome'];
$foto=$row['foto'];
$vew=$row['vew'];
$tkm=$row['tkm'];
$modo=$row['modo'];
$pxid= $row['id'];
$i++;
?>
<div class="col-md-3 sb-preview text-center">
<div class="card h-100">
<div id="vew">
<span class="glyphicon glyphicon-eye-open"></span>: <?php echo e($vew); ?>
</div>
<a class="sb-preview-img" href="<?php ?>">
<img class="card-img-top" src="../_img/<?php echo e($foto) ?>" style="width:100%;">
</a>
<div class="card-body">
<h3 class="card-title">
<?php echo e($nome) ?>
<?php if($modo == 1){ ?>
<span class="glyphicon glyphicon-film"></span>
<?php }else if($modo == 2){?>
<span class="glyphicon glyphicon-camera"></span>
<?php }else{ ?>
<span class="glyphicon glyphicon-header"></span>
<?php } ?>
</h3>
</div>
</div>
</div>
<?php
if($i==4){
?>
</div>
<?php
$i=0;
?>
<div class="row">
<?php
}
if($numrow>12){
$_SESSION['pg']=$pxid;
}
}
?>
<?php
if($numrow>12){
if($i>0 and $i<4 ){
?>
</div>
<?php
}
?>
<div class="row">
<nav class="text-center">
<ul class="pagination pagination-sm">
<?php
$pg=$numrow/12;
$pg = ceil($pg);
//echo $pg;
for($i=1;$pg>=$i;$i++){
if($i==1){
?>
<li><a href="?PS=<?php echo e($_GET['PS']) ?>&PG=0">1</a></li>
<?php
}else{
?>
<li><a href="?PS=<?php echo e($_GET['PS']) ?>&PG=<?php echo e($i)?>"><?php echo e($i)?></a></li>
<?php
}
}
?>
</ul>
</nav>
</div>
<?php
}
?>
</div>
<?php
}else{
}
?>