v2.5.2
Giriş yap

PHP İLE SAYFALANDIRMA YAPMAK

umutkalender
517 defa görüntülendi

php ile sayfalandırma nasil yapılır yardımcı olabilir misiniz?

gokcin
896 gün önce

$Sayfa          = @intval($_GET['page']); if(!$Sayfa) $Sayfa = 1;
$ToplamVeri     = $db->query('SELECT COUNT(*) FROM table')->fetchColumn(); 
$Limit          = 20;
$Sayfa_Sayisi   = ceil($ToplamVeri/$Limit); if($Sayfa > $Sayfa_Sayisi){$Sayfa = 1;}
$Goster         = $Sayfa * $Limit - $Limit;
$GorunenSayfa   = 5;

$sql        = $db->prepare("SELECT * FROM table ORDER BY id DESC LIMIT $Goster,$Limit");
$sql_total  = $sql->rowCount();
$sql->execute();
while ($row=$sql->fetch(PDO::FETCH_ASSOC)) {
    //Kendi sorgu alanın
}



for($i = $Sayfa - $GorunenSayfa; $i < $Sayfa + $GorunenSayfa +1; $i++){ 
    if($i > 0 and $i <= $Sayfa_Sayisi){
        if($i == $Sayfa){
            $button.= '<li class="page-item active"><a class="page-link" href="#">'.$i.'</a></li>';
        }else{
            $button.= '<li class="page-item"><a class="page-link" href="?page='.$i.'">'.$i.'</a></li>';
        }
    }
}

if ($Sayfa==$Sayfa_Sayisi) {

    $page_son = '
    <li class="page-item disabled">
    <a class="page-link" href="#">
    Son Sayfa <svg xmlns="http://www.w3.org/2000/svg" style="width: 1.25rem;height: 1.25rem;font-size: 1.25rem;vertical-align: bottom;stroke-width: 1.5;" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z"></path><polyline points="9 6 15 12 9 18"></polyline></svg>
    </a>
    </li>';
} else {

    $page_son.= '<li class="page-item"><a class="page-link" href="?page='.$Sayfa_Sayisi.'"> Son Sayfa <svg xmlns="http://www.w3.org/2000/svg" style="width: 1.25rem;height: 1.25rem;font-size: 1.25rem;vertical-align: bottom;stroke-width: 1.5;" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z"></path><polyline points="9 6 15 12 9 18"></polyline></svg></a></li> '; 
}

if ($Sayfa==1) {

    $page_one.= '<li class="page-item disabled"><a class="page-link" href="#" tabindex="-1"><svg xmlns="http://www.w3.org/2000/svg" style="width: 1.25rem;height: 1.25rem;font-size: 1.25rem;vertical-align: bottom;stroke-width: 1.5;" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z"></path><polyline points="15 6 9 12 15 18"></polyline></svg> Başa Dön</a></li>';
} else {

    $page_one.= '<li class="page-item"><a class="page-link" href="?page=1" tabindex="-1"><svg xmlns="http://www.w3.org/2000/svg" style="width: 1.25rem;height: 1.25rem;font-size: 1.25rem;vertical-align: bottom;stroke-width: 1.5;" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z"></path><polyline points="15 6 9 12 15 18"></polyline></svg> Başa Dön</a></li>'; 
}


<nav class="card-footer d-flex align-items-center">
    <ul class="pagination m-0 ms-auto">
        <?php echo $page_one;?>
        <?php echo $button;?>
        <?php echo $page_son;?>
    </ul>
</nav>