PHP sayfalandırmada kodu gerekir?

3 Cevap php

SQL deyimleri için bir veri Array, değil PHP bir Sayfalandırması script / sınıf / yardımcısı arayın. Birisi bir çözüm biliyor musunuz?

3 Cevap

Kafamın üst Off SPL parçasıdır LimitIterator bakmak olabilir.

Eğer sonuç geniş bir koleksiyona sahip Sayfalandırması istemci tarafında uygulanması iyi şans olabilir SQL içermeyen bir koleksiyon pagination arıyorsanız. Genellikle sql sonraki / önceki sonuçların takip edileceği - Ben sadece php veri sonuçlarının tek bir blok varsa o zaman gerçekten tekrar ve tekrar yeniden olmak istemiyorum düşünüyorum.

Bu jQuery pagination plugin yararlı olabilir?

basic pagination you can tweak to whatever you need. the second code snipped would be the part in your view. You could easily take this and make it more generic to be used whenever you needed it.

// !!! make sure that page is set as a url param
if( !isset( $_GET[ 'page' ] )){
   $_GET[ 'page' ] = 0;
}

// find out how many rows there are total
$totalRows = mysql_query( "SELECT COUNT(*) FROM table" ); 
$totalRows = mysql_num_rows( $totalRows );
// find out how many pages there will be
$numPages = floor( $totalRows  / $perPage );

$perPage = 15;
$offset = floor( $_GET[ 'page' ] * $perPage );

// get just the data you need for the page you are on
$pageData = mysql_query( "SELECT * FROM table LIMIT $perPage OFFSET $offset" ); 

sonra sayfadaki bağlantıları oluşturmak için

// get the current url to replace

for ($i=0; $i <= $numPages; $i++) {             
   if( $_GET[ 'page'] != $i ){          
       echo '<a href="/yourpage.php?page=' . $i + 1 . '">page '.( $i+1 ).'</a>';
    }else{      
       echo "page " . ( $i+1 );
   }
}