具有随机排序的 PHP MySQL 分页
在网站上实现带分页的搜索功能时,解决与随机排序相关的问题至关重要结果的排序。本文提供了以下挑战的解决方案:
示例:
<code class="php"><?php session_start(); // Generate a unique seed value for the first page if (!isset($_SESSION['seed'])) { $_SESSION['seed'] = rand(1, 1000); } // Exclude previously seen results $excludedIds = array(); if (isset($_SESSION['seenResults'])) { $excludedIds = $_SESSION['seenResults']; } // Query with random ordering and exclusion $query = "SELECT * FROM table WHERE id NOT IN ('" . implode("', '", $excludedIds) . "') ORDER BY RAND(" . $_SESSION['seed'] . ") LIMIT 10";</code>
以上是如何在 PHP 和 MySQL 中实现随机排序分页?的详细内容。更多信息请关注PHP中文网其他相关文章!