How do I display current user position in leaderboard?

Get help using Construct 2

Post » Mon Nov 28, 2016 6:17 am

Hi Everyone,

I am currently trying to create leaderbaord by following this tutorial "https://www.scirra.com/tutorials/4839/creating-your-own-leaderboard-highscores-easy-and-free-php-mysql"

Can anyone please tell me how to display position of ranking of current user/scorer. (I.e. If current user is standing at ranking 101th position in leaderboard then how to display the ranking(101th) below 10 top scores table.

sample capx is attached in the tutorial itself. I am using same.

Need help very urgently.

Regards,
Jatin
B
49
S
14
Posts: 75
Reputation: 3,590

Post » Mon Nov 28, 2016 10:09 pm

You should be able to have the MySQL engine sort the results of a SELECT script.

Like this:
https://www.tutorialspoint.com/mysql/my ... esults.htm
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,415
Reputation: 4,824

Post » Tue Nov 29, 2016 6:20 am

gumshoe2029 wrote:You should be able to have the MySQL engine sort the results of a SELECT script.

Like this:
https://www.tutorialspoint.com/mysql/my ... esults.htm


Hi Thanks a lot for response.

But I have no knowledge about php and mysql. I was following sample capx file used in tutorial. Currently it is displaying only two columns, name and score. Can you help me in displaying 3rd element which is ranking. In sample author has used array. How can I turn it to use 3 columns instead of 3. and how to fetch from db and display in construct 2 file.

I will be really greatful to you if you can help me in modifying the sample capx of tutorial.

Thanks in advance.
Jatin
B
49
S
14
Posts: 75
Reputation: 3,590

Post » Tue Nov 29, 2016 5:05 pm

Sorry, I was under the impression that you had some knowledge of database operation.

Okay, you see in this image:
Image
towards the bottom where he has the parameter $sql="SELECT * FROM scores ORDER BY score DESC LIMIT 10"

You simply need to remove the "LIMIT 10" and it will return all of the scores in the database ordered by score descending.

That is what that select statement is asking for:

SELECT (tells the database to get data)
* (tells it to return all data)
FROM scores (from the "scores" table)
ORDER BY score (order the data lexicographically by score)
DESC (in a descending order from highest to lowest)
LIMIT 10 (only return the top 10 scores)

jatin1726 wrote:How can I turn it to use 3 columns instead of 3.


Also this question makes no sense.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,415
Reputation: 4,824

Post » Fri Dec 02, 2016 7:04 am

gumshoe2029 wrote:Sorry, I was under the impression that you had some knowledge of database operation.

Okay, you see in this image:
Image
towards the bottom where he has the parameter $sql="SELECT * FROM scores ORDER BY score DESC LIMIT 10"

You simply need to remove the "LIMIT 10" and it will return all of the scores in the database ordered by score descending.

That is what that select statement is asking for:

SELECT (tells the database to get data)
* (tells it to return all data)
FROM scores (from the "scores" table)
ORDER BY score (order the data lexicographically by score)
DESC (in a descending order from highest to lowest)
LIMIT 10 (only return the top 10 scores)

jatin1726 wrote:How can I turn it to use 3 columns instead of 3.


Also this question makes no sense.



Thanks a lot Gumshoe for such details replay, really really helpful and I understood that removing the limit of 10 will display all results. But in sample capx creator is using array and I have made it 10x10 to display data in 5 lines in text boxes. If I will try to show all list (might be scrolable) then how it can be done (I think it needs to create scrollalbe list with data filling from server, right)? any help in this? To cut short the things I am sharing screenshot of leaderboard similar to my requirement. I will be very thankful to you if can help me in getting close to this.

Regarding colum 3 to 3 statement, it was my mistake. Actually creator is using 2 column (through array) and I need 3 colmn (index no. , player name, score). Also explaining this through screenshot.


Thanks again.
waiting for your reply. below is screenshot of required leader board and question which I have.
Image
B
49
S
14
Posts: 75
Reputation: 3,590

Post » Fri Dec 02, 2016 11:04 am

It's easy, first display that top 10 select. Under it add another textbox or whatever C2 object you use to display the first 10, so add one under it (i guess it's a textbox).
Make it smaller and assign the following select to it

SELECT
*
FROM scores
where Name = <C2 variable holding his nickname>

This will display one line with the player's nickname, and since you put the textbox under it, it will show as separate.


It is possible to make a select to display everything in the same C2 object but i'm in a bit of a hurry right now. I'll see if I can make that work as well a bit later.
Black Bobby The Hole Greenlit with 303 votes.
B
36
S
8
G
1
Posts: 163
Reputation: 3,029

Post » Fri Dec 02, 2016 11:07 am

@gumshoe2029 i really hope those are not your real DB credentials
Black Bobby The Hole Greenlit with 303 votes.
B
36
S
8
G
1
Posts: 163
Reputation: 3,029

Post » Mon Dec 05, 2016 12:20 pm

Je Fawk wrote:It's easy, first display that top 10 select. Under it add another textbox or whatever C2 object you use to display the first 10, so add one under it (i guess it's a textbox).
Make it smaller and assign the following select to it

SELECT
*
FROM scores
where Name = <C2 variable holding his nickname>

This will display one line with the player's nickname, and since you put the textbox under it, it will show as separate.


It is possible to make a select to display everything in the same C2 object but i'm in a bit of a hurry right now. I'll see if I can make that work as well a bit later.


Hi,

Thanks for response. As I shared above I hve no idea about php and sql. Can you help me by updating sample capx (of tutorial) to the one showing current user id? That will be big help for me.
B
49
S
14
Posts: 75
Reputation: 3,590

Post » Mon Dec 05, 2016 9:05 pm

Je Fawk wrote:@gumshoe2029 i really hope those are not your real DB credentials


Not my database, so not my problem. :-p
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,415
Reputation: 4,824

Post » Mon Dec 05, 2016 9:20 pm

@jatin1726
I actually ran into this same problem, and I found a clever solution from someone whose handle I forget now...
But here you go:
https://drive.google.com/open?id=0B-xiq ... mliTUJ1SGM

To get your player at the bottom just add another Text field and use Array.At(Array.indexOf(playerName)) & ": " & myScore.

Or you could even use a 2D array and store as many other columns as you need in your array, just use the X=0 column to store your indices (like player id).

Je Fawk wrote:SELECT
*
FROM scores
where Name = <C2 variable holding his nickname>


You should use caution in using this unless you can guarantee that your nicknames are unique, otherwise confusion will ensue. Most databases use a player index or player id to ensure uniqueness in your database keys.

If you have two players named "jatin" then that SQL statement will return two rows of data! Will the real jatin please stand up?
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,415
Reputation: 4,824


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, David181, fens and 8 guests