1

I'm working on a project where I have to show the leaderboard of players. But when wrote the below code, It shows the ranks with 2, 4, 6, 8, ... But not the odd numbered ranks. Can anyone tell me "What's wrong in this ?"

$query1_string = "CREATE VIEW Leaderboard AS SELECT Name, Points, PhoneNo
                  FROM user ORDER BY Points DESC";
$query2_string = "set @rank = 0";
$query3_string = "SELECT @rank := @rank + 1 as Rank, Name, Points
                  FROM Leaderboard";
$query5_string = "DROP VIEW Leaderboard";

// Doing the queries
$query1 = mysqli_query($con, $query1_string) or die(mysqli_error($con));
$query2 = mysqli_query($con, $query2_string) or die(mysqli_error($con));
$query3 = mysqli_query($con, $query3_string) or die(mysqli_error($con));
// Initializing the count
$count = 0;

//Making an array of strings including Rank, Name and Points of the Top 5 Players
while (($count < 5) && (mysqli_fetch_array($query3, MYSQL_NUM))) {
    $row = mysqli_fetch_array($query3, MYSQL_NUM);
    $results[$count] = $row[0] . "   " . $row[1] . "    " . $row[2];
    $count++;
}

// Dropping the view.
$end_query = mysqli_query($con, $query5_string) or die(mysqli_error($con));

//Returning the array
$leader = implode("\n", $results);
echo $leader;
2
  • it is showing the even and you want to show the odd right ? Commented Dec 30, 2014 at 2:06
  • I want show the both. @яша Commented Dec 30, 2014 at 2:06

1 Answer 1

3

You are executing the query3 two times and displying the data retrieved from second execution

while (($count < 5) && (mysqli_fetch_array($query3, MYSQL_NUM))) {
    $row = mysqli_fetch_array($query3, MYSQL_NUM);
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah ! That's it. I was blinded :) Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.