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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.