Ben Jonathan Sampson Ben üzerinde PAGINATION istediğiniz her sayfada yazmak zorunda zorunda kalmamak, bir fonksiyon içine (lazım onun mükemmel video dersler için kredi vermek) tarafından yapılan bir Sayfalandırması komut dosyası yapmak için çalışıyorum, bu yüzden can Her sayfada sayfalama kodu kalmadan o benim tüm site üzerinde kullanabilirsiniz :)
Ben fonksiyonu ile sorgu geçmek düşündüm ve iyi çalışır:
function pagination_query($query, $table = false, $column = false)
{
// Create some variables
$pageNumber = (isset($_GET['page']) && is_numeric($_GET['page'])) ? $_GET['page'] : 1;
// Establish number of results per page
$perPage = 5;
// Establish a padding value
$padding = 3;
// Get Start index of results
$startIndex = ($pageNumber * $perPage) - $perPage;
// Get total number of database entries
$totalCount = "SELECT COUNT(*) as 'Total' FROM $table $column";
$rsCount = mysql_query($totalCount) or die (mysql_error());
$rowCount = mysql_fetch_object($rsCount);
----- non essential stuff removed -----
// Get page results
$sql = "$query
LIMIT $startIndex, $perPage";
// Get result set
$query = mysql_query($sql) or die(mysql_error());
return $query;
}
Kullanımda:
$query = pagination_query("SELECT id, message
FROM posts WHERE topicid = 1
ORDER BY id", 'posts', 'WHERE topicid = 1');
if (mysql_num_rows($query)> 0) {
// Show the results
while($row = mysql_fetch_object($query)) {
print "<div>";
print $row->id;
print ": ";
print substr($row->message, 0, strrpos(substr($row->message, 0, 50), ' ')) . '...';
print "</div>";
}
}
I just figured out that with this, I can only print the links in one place on the page. Any ideas?
Siz benim çözüm ne düşünüyorsunuz? Bir akıllı ve daha iyi bir yolu var mı?