Lamez Posted March 25, 2008 Share Posted March 25, 2008 Alright on my member's list, I am trying to sort them, and have pagination, but it is not working. with out sorting, I have it like this ?p=list&page=1 so I want it like this ?p=sort=all&list&page=1 how? here is my code, any suggestions? <?php $num = 2; include ("include/session.php"); $page = isset($_GET['page']) && is_numeric($_GET['page']) && $_GET['page'] >= 1 ? $_GET['page'] : 1; $per_page = $num; $count_q = mysql_query("SELECT COUNT(username) FROM ".TBL_USERS." ORDER BY username DESC"); $count_r = mysql_fetch_row($count_q); $count = $count_r[0]; if($page > ceil($count/$per_page)) $page = 1; $limit_min = ($page-1)*$per_page; $query = mysql_query("SELECT * FROM ".TBL_USERS." ORDER BY username DESC LIMIT {$limit_min}, {$per_page}"); ?> <script type="text/JavaScript"> <!-- function MM_jumpMenu(targ,selObj,restore){ //v3.0 eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); if (restore) selObj.selectedIndex=0; } //--> </script> <table width="33%" border="0" align="left"> <form aciton="<?php $_SERVER['PHP_SELF']?>" method="get"> <tr> <td width="12%"></td> <td width="16%">Sort By: </td> <td colspan="2"><select name="sort"> <option value="all&" selected="selected">All Members</option> <option value="online">Online</option> <option value="offline">Offline</option> <option value="a">Username A-Z</option> <option value="z">Username Z-A</option> <option value="last">Last Logged In</option> </select> <label> <input type="submit" name="<?php echo md5("sort"); ?>" value="Sort" /> </label></td> </tr> </form> <tr> <td colspan="2"><strong>Username</strong></td> <td width="35%" align="left"><strong>E-Mail</strong></td> <td width="37%" align="left"><strong>Status</strong></td> </tr> <?php $getlink = $_GET["sort"]; if ($getlink == "all&") { while($rs = mysql_fetch_assoc($query)) { $users = $rs['username']; ?> <tr> <td colspan="2" align="left"><?php echo '<a href="userinfo.php?user='.$users.'">'.$users.'</a>'; ?></td> <td align="left"><?php echo $rs['email']; ?></td> <td align="left"> <?php $que = mysql_query("SELECT u.username FROM ".TBL_USERS." u INNER JOIN ".TBL_ACTIVE_USERS." a ON a.username=u.username WHERE a.timestamp < (NOW() - INTERVAL 5 MINUTE) AND u.username= '$users'")or die(mysql_error()); if (mysql_num_rows($que) > 0) { echo "<font color=\"#04db04\">Online</font><br />"; }else{ echo "<font color=\"#FF0000\">Offline<br /></font>"; } echo '</td>'; echo '</tr>'; } } ?> <tr> <td colspan="4"> <?php $limit2 = $per_page; $q = "SELECT username FROM ".TBL_USERS; $r = mysql_query($q); $num = ceil(mysql_num_rows($r) / $limit2); if($num != 1) { for($i = 1; $i <= $num; $i++) { /*if($page / $limit2 != $i)*/ echo "[<a href='?p=list&page=".$i."'>".$i."</a>] "; //else echo "[<b>".$i."</b>] "; } } ?> </td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
Lamez Posted March 25, 2008 Author Share Posted March 25, 2008 sorry for wasting a thread, I got it, here is my code so far: <?php $num = 2; include ("include/session.php"); $page = isset($_GET['page']) && is_numeric($_GET['page']) && $_GET['page'] >= 1 ? $_GET['page'] : 1; $per_page = $num; $count_q = mysql_query("SELECT COUNT(username) FROM ".TBL_USERS." ORDER BY username DESC"); $count_r = mysql_fetch_row($count_q); $count = $count_r[0]; if($page > ceil($count/$per_page)) $page = 1; $limit_min = ($page-1)*$per_page; $query = mysql_query("SELECT * FROM ".TBL_USERS." ORDER BY username DESC LIMIT {$limit_min}, {$per_page}"); ?> <table width="33%" border="0" align="left"> <form aciton="<?php $_SERVER['PHP_SELF']?>" method="get"> <tr> <td width="12%"></td> <td width="16%">Sort By: </td> <td colspan="2"><select name="sort"> <option value="all&" selected="selected">All Members</option> <option value="online">Online</option> <option value="offline">Offline</option> <option value="a">Username A-Z</option> <option value="z">Username Z-A</option> <option value="last">Last Logged In</option> </select> <label> <input type="submit" name="Sort" value="Sort" /> </label></td> </tr> </form> <tr> <td colspan="2"><strong>Username</strong></td> <td width="35%" align="left"><strong>E-Mail</strong></td> <td width="37%" align="left"><strong>Status</strong></td> </tr> <?php $getlink = $_GET["sort"]; if ($getlink == "all&") { while($rs = mysql_fetch_assoc($query)) { $users = $rs['username']; ?> <tr> <td colspan="2" align="left"><?php echo '<a href="userinfo.php?user='.$users.'">'.$users.'</a>'; ?></td> <td align="left"><?php echo $rs['email']; ?></td> <td align="left"> <?php $que = mysql_query("SELECT u.username FROM ".TBL_USERS." u INNER JOIN ".TBL_ACTIVE_USERS." a ON a.username=u.username WHERE a.timestamp < (NOW() - INTERVAL 5 MINUTE) AND u.username= '$users'")or die(mysql_error()); if (mysql_num_rows($que) > 0) { echo "<font color=\"#04db04\">Online</font><br />"; }else{ echo "<font color=\"#FF0000\">Offline<br /></font>"; } echo '</td>'; echo '</tr>'; } } ?> <tr> <td colspan="4"> <?php $limit2 = $per_page; $q = "SELECT username FROM ".TBL_USERS; $r = mysql_query($q); $num = ceil(mysql_num_rows($r) / $limit2); if($num != 1) { for($i = 1; $i <= $num; $i++) { if ($getlink == "all&"){ $var = "sort=all%26&Sort=Sort"; } /*if($page / $limit2 != $i)*/ echo "[<a href='?".$var."&list&page=".$i."'>".$i."</a>] "; //else echo "[<b>".$i."</b>] "; } } ?> </td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.