本文介绍了如何在分页项目中实现最后步骤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为我的网站执行我的第一个分页实作。我觉得我很近,只是混淆了我的逻辑或错误的位置或一些变量的实际价值。
I am doing my first pagination implementation to my site. I feel like I am very close and just confusing my logic or mistaking the placement or actual value of some variables.
这是代码:
$pgsize_wave = 40; $pg_wave = (is_numeric($_GET["p"]) ? $_GET["p"] : 1); $start = ($pg_wave-1)*$pgsize_wave; $waves = mysql_query("SELECT * FROM `CysticAirwaves` LIMIT $start, $pgsize_wave"); $waves_total = mysql_query("SELECT COUNT(1) FROM `CysticAirwaves`"); $waves_total = mysql_fetch_row($waves_total); $waves_total = $waves_total[0]; $max_pages = $waves_total / $pgsize_wave; $max_pages = ceil($waves_total/$pgsize_waves); ?> <div id="all_page_turn"> <ul> <?php if($waves_total > 40 && $pg_wave >= 40) { ?> <li class="PreviousPageBlog round_10px"> <a href="Airwave_build.php?id=<?php echo $pg_wave - 40); ?>">Previous Page</a> </li> <?php } ?> <?php if($waves_total > 40 && $pg_wave < ($waves_total-40)) { ?> <li class="NextPageBlog round_10px"> <a href="Airwave_build.php?id=<?php echo ($pg_wave + 40); ?>">Next Page</a> </li> <?php } ?> </ul> </div>为了澄清任何混乱,airwave是一个用户的信息,我想限制每页40 。如果它帮助这里是查询,在同一页上拉一个airwave:
To clarify any confusion, an airwave is a post from a user and I want to limit 40 per page. If it helps here is the query that pulls an airwave on the same page:
$query = "SELECT * FROM `CysticAirwaves` WHERE `FromUserID` = `ToUserID` AND `status` = 'active' ORDER BY `date` DESC, `time` DESC"; $request = mysql_query($query,$connection); $counter = 0; while($result = mysql_fetch_array($request)) { $replies_q = "SELECT COUNT(`id`) FROM `CysticAirwaves_replies` WHERE `AirwaveID` = '" . $result['id'] . "' && `status` = 'active'"; $request2 = mysql_query($replies_q,$connection); $replies = mysql_fetch_array($request2); $replies_num = $replies['COUNT(`id`)']; $counter++; $waver = new User($result['FromUserID']);非常感谢。
推荐答案这是伪代码,但希望解释逻辑。
This is pseudo code but hopefully explains the logic.
$total = SELECT COUNT(*) FROM `waves` $currentPage = 1 // changes through page parameter in URL $wavesPerPage = 40 $totalPages = ceil($total / $wavesPerPage) $offset = ($wavesPerPage * ($currentPage - 1)) + 1 $waves = mysql_query("SELECT * FROM `waves` LIMIT $offset, $wavesPerPage"); while ($row = mysql_fetch_assoc($waves)) { echo $row['wave'] … }要输出分页链接:
if ($totalPages > 1) { if ($currentPage > 1) { printf('<a href="waves.php?page=%u">Previous</a>', $currentPage - 1); } for ($i = 1; $i <= $totalPages; $i++) { $class = ($i == $currentPage) ? 'selected' : null; printf('<a href="waves.php?page=%1$u" class="%2$s">Page %1$u</a>', $i, $class); } if ($currentPage < $totalPages) { printf('<a href="waves.php?page=%u">Next</a>', $currentPage + 1); } }更多推荐
如何在分页项目中实现最后步骤?
发布评论