Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6469403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:59:12+00:00 2026-05-25T05:59:12+00:00

This is my script for the paging on my site when the user clicks

  • 0

This is my script for the paging on my site when the user clicks on a league.
The league is then echoed to the screen, and if the league is over 3 rows then it splits it up in to several pages.
What I am doing after is depending on where the user is in the league (the SQL query is using ORDER BY the total points column in the table), e.g if the user is on page one of the league table then for it to display that page first, but if the user is on page 3 of the league table then for that page to displayed first.

Does anyone know a way in order for me to achieve this?

//Recently updated from answer

$sql="SELECT members.username, members.total_points FROM members, members_leagues WHERE members.username = members_leagues.username AND 
        members_leagues.sub_league = '$chosenleague' ORDER BY members.total_points DESC";

$result=mysql_query($sql);

$i = 0;
$found = false;
$team_position = 0;

while (!$found && $row = mysql_fetch_row($result)){
   if ($row[username] == $_SESSION[username]) {
   $team_position = $i;
   $found = true;
   }
 $i++;
}

$rowsPerPage = 3;

$pageNum =  ceil($i/$rowsPerPage);
//end of recently updated

if(isset($_GET['page']))
    $pageNum = $_GET['page'];

$offset = ($pageNum - 1) * $rowsPerPage;
$counter = $offset + 1;

$query = " SELECT members.username, members.teamname, members.total_points, FROM members, members_leagues WHERE members.username = members_leagues.username AND members_leagues.sub_league = '$chosenleague' ORDER BY members.total_points DESC " . " LIMIT $offset, $rowsPerPage";

$result = mysql_query($query) or die('Error, query failed');

echo "<h3 style=\"color:red;\">$chosenleague</h3>";
echo "<table>";
echo "<tr><th>Position</th>";
echo "<th>Team</th>";
echo "<th>Points/Overall</th>";
echo "<th>Points/Last Race</th>";
echo "<th>Team Setup</th></tr>";

while($row = mysql_fetch_array($result))
{
    if($row[username] == $_SESSION[username])
        echo "<tr style=\"color:red;\"><td>";
    else
        echo "<tr><td>";

    echo $counter;
    echo "</td><td>";
    echo $row[teamname];
    echo "</td><td>";
    echo $row[total_points];
    echo "</td><td>";
    echo "</td><td>";
    echo "</td></tr>";
    $counter++;
}
echo "</table>";

$query   = "SELECT COUNT(members.username) AS numrows FROM members, members_leagues WHERE members.username = members_leagues.username 
AND members_leagues.sub_league = '$chosenleague'";

$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];

$maxPage = ceil($numrows/$rowsPerPage);

$self = $_SERVER['PHP_SELF'];
$nav  = '';

if ($pageNum > 1)
{
    $page  = $pageNum - 1;

    $prev  = " <a href=\"$self?league=". rawurlencode($chosenleague) . "&page=". rawurlencode($page) . "\"><< Prev</a> ";
    $first = " <a href=\"$self?league=". rawurlencode($chosenleague) . "&page=". rawurlencode(1) . "\">First</a> ";
}
else
{
    $prev  = ''; 
    $first = ''; 
}

if ($pageNum < $maxPage)
{
    $page = $pageNum + 1;
    $next = " <a href=\"$self?league=". rawurlencode($chosenleague) . "&page=". rawurlencode($page) . "\">Next >></a> ";
    $last = " <a href=\"$self?league=". rawurlencode($chosenleague) . "&page=". rawurlencode($maxPage) . "\">Last</a> ";
}
else
{
    $next = '';
    $last = ''; 
}

echo "<div id=\"pagenum\">Page $pageNum of $maxPage &nbsp;". $first . $last . $prev . $next ."</div>";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T05:59:13+00:00Added an answer on May 25, 2026 at 5:59 am

    You can do it via mysql or php:

    With PHP:

    Found the position of the requested record in the array, then calculate the page you have to extract and execute the corresponding query. Something like.

    $i = 0;
    $found = false;
    $team_position = 0;
    
    while (!$found && $row = mysql_fetch_row) {
      if ($row['team'] == 'team_your_searching_for') {
        $team_position = $i;
        $found = true;
      }
      $i++;
    }
    
    //calculate $top and $bottom
    ...
    
    $sql = "SELECT * FROM members LIMIT $top, $bottom;";
    ...
    

    With MySQL:

    You can create a query that generates an autoincrement value and another that selects from the other’s result. I mean

    -- get the the selected member's position
    SELECT team, pos FROM (SELECT team, points, @position = @position + 1 AS pos FROM members ORDER BY points) WHERE team = @the_team_your_searching_for;
    
    -- get the nr of members
    SELECT COUNT(*) FROM members;
    
    ...
    
    -- calculate the page you wanna extract (@top, @bottom), and extract it
    SELECT * FROM members LIMIT @top, @bottom;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been doing some customization to this jQuery paging script I found here
This script uses jsdom and jquery to get the value of an a tag's
For this script, it checks to see if the file is a microsoft words
I have this script which basically toggles a bgColor class on and off so
I got this script called rapidshare link checker v2 php by Bigfish At the
Can someone explain why this script throws an exception? $byteArray = @(1,2,3) write-Output (
I want to execute this script (view source) that uses Google Translate AJAX API
I've got this script on my website : $(document).ready(function() { function filterPath(string) { return
I found this script: <script language=Javascript TYPE=text/javascript> var container = document.getElementById('dl'); var seconds =
I want help on this script I am making... I want my website to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.