Jump to content

Page Numbering - Limit by Username


affc

Recommended Posts

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);
?>

Link to comment
https://forums.phpfreaks.com/topic/155807-page-numbering-limit-by-username/
Share on other sites

<?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);
?>

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 :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.