PHP 與MySQL 分頁:綜合指南
問題:
問題:問題:
<code class="php"><?php // Insert your MySQL connection code here // Define variables $perPage = 10; $page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1; $startAt = $perPage * ($page - 1); // Get total number of rows $query = "SELECT COUNT(*) as total FROM redirect WHERE user_id = '".$_SESSION['user_id']."'"; $r = mysql_fetch_assoc(mysql_query($query)); // Calculate total number of pages $totalPages = ceil($r['total'] / $perPage); // Generate pagination links $links = ""; for ($i = 1; $i <= $totalPages; $i++) { $links .= ($i != $page ) ? "<a href='index.php?page=$i'>Page $i</a> " : "$page "; } // Execute query with pagination applied $query = "SELECT * FROM 'redirect' WHERE 'user_id'= \''.$_SESSION['user_id'].' \' ORDER BY 'timestamp' LIMIT $startAt, $perPage"; $r = mysql_query($query); // Display results ... // Echo pagination links echo $links; // show links to other pages</code>
以上是如何在 PHP 和 MySQL 中為「重定向」表實作分頁?的詳細內容。更多資訊請關注PHP中文網其他相關文章!