嗨,我是新程序员
i have a simple pagination which works fine, i have sorting options for sorting my recordset result by id, title etc which is also working fine, the codes are below.
我现在要“强”和“强”两个词都“强”两个词,并具备一个功能,在这两个条件上,方格应该起作用。
that is when recordset result is displayed by default pagination should work as before. and when recordset result is sorted by options pagination should work on sorted result too.
我发现了一些东西,代码在下面, 但我不能让它工作。
我的基本记录和分级代码是:
<?php
$table= mytable ;
$pagename = "is-test.php";
$db = mysql_select_db($database,$connection) or trigger_error("SQL", E_USER_ERROR);
$sql1 = "SELECT COUNT(*) FROM $table";
$result1 = mysql_query($sql1, $connection) or trigger_error("SQL", E_USER_ERROR);
$row = mysql_fetch_row($result1);
$numrows = $row[0];
$rowsperpage = 5;
$totalpages = ceil($numrows / $rowsperpage);
if (isset($_GET[ page ]) && is_numeric($_GET[ page ])) {
$currentpage = (int) mysql_real_escape_string($_GET[ page ]);
} else {
$currentpage = 1;
}
if ($currentpage > $totalpages) {
$currentpage = $totalpages;
}
if ($currentpage < 1) {
$currentpage = 1;
}
$orderBy = array( id , title ,);
$order = ;
if (isset($_GET[ orderBy ]) && in_array($_GET[ orderBy ], $orderBy)) {
$order = mysql_real_escape_string($_GET[ orderBy ]);
}else{
$order= id ;
}
$offset = ($currentpage - 1) * $rowsperpage;
$sql2 = "SELECT * FROM $table ORDER BY $order ASC LIMIT $offset, $rowsperpage";
$result2 = mysql_query($sql2, $connection) or trigger_error("SQL", E_USER_ERROR);
$list = mysql_fetch_assoc($result2);
$startrow = ($currentpage-1) * $rowsperpage
我用于排序选项的代码 :
Sort by
<a href="?orderBy=id">id:</a>
<a href="?orderBy=title">title:</a>
我的射程代码是:
if ($currentpage != $totalpages) {
$nextpage = $currentpage + 1;
echo " <li><a href= $pagename?page=$nextpage >Next»»</a></li> ";
}
if($currentpage<$totalpages){
for ($x = ($currentpage - 3); $x < (($currentpage + 3) + 1); $x++) {
if (($x > 0) && ($x <= $totalpages)) {
if ($x == $currentpage) {
echo " <li id= pcurrent ><a href= $pagename?page=$x >$x</a></li>";
} else {
echo " <li><a href= $pagename?page=$x >$x</a></li> ";
}}}
}
if ($currentpage > 1){
$prevpage = $currentpage - 1;
echo " <li><a href= $pagename?page=$prevpage >««Prev</a></li> ";
}
upto now everytthing is working except pagination only paginate defaut recordset resunt not sorted recordset result for that i have to change url parameter for pagination to work on sorting result, so i have changed my pagination links as
if ($currentpage != $totalpages) {
$nextpage = $currentpage + 1;
echo " <li><a href= $pagename?orderBy=$order,page=$nextpage >Next»»</a></li> ";
}
if($currentpage<$totalpages){
for ($x = ($currentpage - 3); $x < (($currentpage + 3) + 1); $x++) {
if (($x > 0) && ($x <= $totalpages)) {
if ($x == $currentpage) {
echo " <li id= pcurrent ><a href= $pagename?orderBy=$order,page=$x >$x</a></li>";
} else {
echo " <li><a href= $pagename?orderBy=$order,page=$x >$x</a></li> ";
}}}
}
if ($currentpage > 1){
$prevpage = $currentpage - 1;
echo " <li><a href= $pagename?page=$prevpage >««Prev</a></li> ";
}
i.e added orderBy=$order in links for pagination, but pagination is not working now, not on default recordset result and not on sorted recordset result.
请你看看我做错了什么