affc Posted April 27, 2009 Share Posted April 27, 2009 Gday, Just a quick one, not sure how to change the following code so that if the GET function has say a username in it, I want the database to display the username selected first and the next 50 members following them in order. But if no username search was conducted then it just shows the normal pages limited from 1 to 50 on each page. <?php $Username = $_GET['username']; $rowsPerPage = 50; $pageNum = 1; if(isset($_GET['page'])) { $pageNum = $_GET['page']; } $offset = ($pageNum - 1) * $rowsPerPage; if($Username){ //Need Help Here, so that the Username selected displays at the top of the Table, and the rest below this Username displaying up to 50 people per page // $sql="SELECT * FROM $tbl_name ORDER BY TOTAL DESC, Username ASC LIMIT $offset, $rowsPerPage WHERE Username='$Username' "; } else{ $sql="SELECT * FROM $tbl_name ORDER BY TOTAL DESC, Username ASC LIMIT $offset, $rowsPerPage"; } $result=mysql_query($sql); ?> Quote Link to comment https://forums.phpfreaks.com/topic/155807-page-numbering-limit-by-username/ Share on other sites More sharing options...
sasa Posted April 27, 2009 Share Posted April 27, 2009 <?php $Username = $_GET['username']; $rowsPerPage = 50; $pageNum = 1; if(isset($_GET['page'])) { $pageNum = $_GET['page']; } $offset = ($pageNum - 1) * $rowsPerPage; $sql = ''; if($Username){ //Need Help Here, so that the Username selected displays at the top of the Table, and the rest below this Username displaying up to 50 people per page // $sql="SELECT * FROM $tbl_name ORDER BY TOTAL DESC, Username ASC LIMIT $offset, $rowsPerPage WHERE Username='$Username' UNION "; } $sql .= "SELECT * FROM $tbl_name ORDER BY TOTAL DESC, Username ASC LIMIT $offset, $rowsPerPage"; $result=mysql_query($sql); ?> Quote Link to comment https://forums.phpfreaks.com/topic/155807-page-numbering-limit-by-username/#findComment-820204 Share on other sites More sharing options...
affc Posted April 27, 2009 Author Share Posted April 27, 2009 Thanks for the reply, what does UNION do by the way? Quote Link to comment https://forums.phpfreaks.com/topic/155807-page-numbering-limit-by-username/#findComment-820219 Share on other sites More sharing options...
affc Posted April 27, 2009 Author Share Posted April 27, 2009 Now that I think of it I am not sure if my code is correct as I still want to display 50 users on each page, just starting with the logged in User at the top of the page and every other user ranked after in order of their position on the Database. Might have to remove the WHERE Username='$Username' and replace with something else but I cant find a script to do what I want, please help Quote Link to comment https://forums.phpfreaks.com/topic/155807-page-numbering-limit-by-username/#findComment-820231 Share on other sites More sharing options...
affc Posted April 30, 2009 Author Share Posted April 30, 2009 Does anyone have any ideas on how this could be done? Im really out of options as to how this can be done, thanx Quote Link to comment https://forums.phpfreaks.com/topic/155807-page-numbering-limit-by-username/#findComment-822441 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.