Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    MYSQL




Ranking Users


i'm trying to rank the users in our site.
table contains:
- userid
- userrates
and with thousands of records.
member with the highest rate goes #1, next is #2 and so on.
i want the query to be like:
Code:
<something goes here> WHERE userid = '$userid' order by userrates desc
from the code above it will show the rank of this user.
then the next user logsin and it shows again his/her ranking.
hope someone understands this
any input is appreaciated




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Ranking Scores
I need to create a query that will sort a bunch of scores in ascending order and then add a column with their rank code from 1 to however many is in the table.
the link below shows an example image of what i need to happen.

A Ranking Leaderboard
I am trying to design and implement an online leaderboard in MySQL and PHP.  Maybe it is because of lack experience in this field but I am really confused on the basics on how this could be achieved.

Correct me if I'm wrong but data is not stored in any order as such in a SQL db.  It is the query you write/code which does the sorting.  How then is it possible to have a leaderboard with rankings on?

For example if I had a basic table with fields of name and points.

You could write a basic query to display the top 10 (or whatever limit you choose) users by points, ascending or desc, etc.  However if you then have a leaderboard with thousands of users on a leaderboard, this wouldn't be practical.  You could obviously pull an individuals record up by using WHERE and the name.

How would I get SQL to output the users ranking?  Surely I cannot do it with an extra field called ranking as everytime the ranking changed ALL records would need to be updated...

Surely this kind of thing has been done before.  I just can't imagine doing this with SQL due to the nature data is stored and then later sorted.

Ranking Results
Im trying to display baseball team stats, along with the ranking for that particular league.
for example, there are 5 teams in the league, Team A has 12 HR, B has 15 HR, C has 3 HR, D has 3, and E has 20.
I want to show on each individual team page their stat, with the rtanking for the league.

Ranking MySQL
I have a query that extracts the last 7 records from a database based on its criteria and have it ordered by its date. What i want to do is add a column in the select statement and put in the numbers from 1 to 7 into the column in this added column.

I'm using the Space(1) as Number function but i am wondering how do I put 1 to 7 in the table. Its pretty much like a ranking system.

Ranking System
I've made a forum and i want to have a ranking system with it. I managed to display a postcount but i also want a few images to be displayed, like if you have made more then 50 posts, it displays 50.jpg or something, how can i accomplish this, in another way then just str_replace()ing all the number of posts?
And how do i display 2, like if you have 50 posts, 50.jpg and if you have 60 posts, 60.jpg.

Create Users Table For Users To Log On Or ...?
I'm pretty new to MySQL, what I was wondering is, for web systems that you need to login to, do developers generally create a users table and store all their users in there, or do they create users such as the root user in mysql ?  If so, how do you add extra fields such as firstname last name etc and how would you go about putting them into groups?

Ranking Leaderboard In MySQL!?
I am trying to design and implement an online leaderboard in MySQL and PHP. Maybe it is because of lack experience in this field but I am really confused on the basics on how this could be achieved.

Correct me if I'm wrong but data is not stored in any order as such in a SQL db. It is the query you write/code which does the sorting. How then is it possible to have a leaderboard with rankings on?

For example if I had a basic table with fields of name and points.

You could write a basic query to display the top 10 (or whatever limit you choose) users by points, ascending or desc, etc. However if you then have a leaderboard with thousands of users on a leaderboard, this wouldn't be practical. You could obviously pull an individuals record up by using WHERE and the name.

How would I get SQL to output the users ranking? Surely I cannot do it with an extra field called ranking as everytime the ranking changed ALL records would need to be updated...

Surely this kind of thing has been done before. I just can't imagine doing this with SQL due to the nature data is stored and then later sorted.

Ranking Query (self Join)
I would like to get a rank (row # of ordered results) of an article based on its average rating in relation to all other articles. I have a ratings table that holds all of the individual votes cast by users (ratingID, articleID, userID, rating). So I need to order the articles by AVG(ratings.rating) and then come up with an individual article's row # to find its ranking.

I know this involves joining the ratings table on itself with a greater than or less than operator, but i'm completely lost when it comes to self-joins. I know this is easy, but there is a small trick to it and i'm clueless.

Ranking For Multiple Columns
A query in my application return several columns with amounts, Now i need to add a ranking to all those columns seperatly.

So the result should be something like this:

ID     Amount1  Ranking1  Amount2 Ranking2
----   -------- --------- ------- --------
135     123.34      4       23.00     3
184     160.23      1       60.89     2
845     140.22      3      100.20     1
987     155.00      2        1.20     4

The ID isnt important here.

The only solution i can think of now is to create a (temp) table, populate it with the query, and then sort it for each ranking and fill the ranking one by one.

Is there a way to get the ranking filled in  the same pass as the amounts are calculated?

Sort And Give Ranking
let say i've have these following table.

tblA
name | marks
-----------------
robert | 39
johnny | 78
bruce | 23
elena | 56
halim | 23

formula, if same marks (see bruce and halim), sort them by name
how to query? expected output showing as below:

no | name | marks
----------------------------
1 | johnny | 78
2 | elena | 56
3 | robert | 39
4 | bruce | 23
5 | halim | 23

Sorting And Put Ranking In Field
I have 3 field in my table Ranking, Name and Score. Is it possible to sort all record to order by Score and put Ranking no. to each record by using query not much?

Scoreboard Ranking System
I have created a high score table that will potentially store > 10000 user scores, and need to determine ranking for items pulled out. Ther have been posts detailing how to do this when selecting ALL records, but in my case, I need to pull out specific rows, and determine their rank against the entire table.
For instance, a user gets a high score that would rank them at #1200, I need to pull out their score, as well as the 3 above and 3 below. I accomplished this by storing the insert_id, and selecting rows where the score is above and below (in seperate queries), but this makes it quite impossible to get a rank.
An alternative method is having a rank column and updating it every time a new score is added, but if it cant be done in one query, it would be a very inefficient method.
Does anyone have any solutions on how to approach this? I am using mysql 3.23, so I dont have use of sub-queries.

Ranking System: Retrieving Results Around Your Rank
I'm building a ranking system for a game. I'm trying to determine the best way to select a players rank, and then display the records around that players ranking.

For instance:

Username | Rank
steve | 6000
bob | 5000
jane | 4000
chris | 3000
brian | 2000
tim | 1000
molly | 0

Assuming chris is the current player, I want to select his rank, and then run a query that returns the two players ranked higher than him, and the two players ranked lower than him. So the query would return the following:


bob | 5000
jane | 4000
chris | 3000 //I'd rather leave his own rank out.. but it's not bad like this.
brian | 2000
tim | 1000

What I can't figure out how to do, is determine the row that is specific to Chris's rank. I would need to define a starting point (-2 rows from Chris), and an end point (+2 rows from Chris), order by and limit the results... what I can't figure out though, is how to get the specific row number to start from.

For instance, lets say Chris is row 583 of my database... how do I retrieve that number?


Ranking Student Grade? With Subquery/subselect?
I am a mySQL newbie here and have some problem defining the mySQL 4.0.14
or 3.23 SQL to get student grade ranking where tied grade have the same
rank.

I used to set it through MS Access 2002 and use this kind of query:

SELECT nilai.studentNIS, nilai.studenttestmark,
(SELECT COUNT(*) FROM tblStudentGrades
WHERE [studenttestmark]>[Nilai].[studenttestmark];)+1 AS NomorUrut FROM
tblStudentGrades AS nilai ORDER BY nilai.studenttestmark DESC;

I've been looking around mySQL documentation and read that subquery can
be redefined as INNER JOIN or using two SQL statement via variable? I
have no idea on the basics of how to set it out though.

Could one of you please help give a me a sample on how this kind of
query should be done on mySQL? Is it possible to do it in single line?
And without having to use PHP/Perl scripts?

Or maybe I should have approach it differently?

Full-Text Search: Truncation Operator And Relevance Ranking?
We would like to begin supporting the truncation operator on our website's search engine--however, we still require the results to be sorted by relevance. If a client enters "televis*" into the search engine, and we perform the search in boolean mode, pages containing "television", "televise", "televised", etc will be returned. However, because it is a boolean mode search, all rows will have a relevancy value of 1.

A user-provided "workaround" on the MySQL site said to use the same keywords but NOT in boolean mode to get a usable relevance ranking. However, a standard fulltext search for "televis" or "televis*" will return no rows.

Users
This is my first time with MySQL need a point in the right direction ;).
I have a private page where only one user can access. On the page there is a number beside the number there is a button. Each time the user presses the button the number goes one down (and the value should stay like this it shouldn't return when the user comes back!) when it is zero the button is disabled.

Edited 1 time(s). Last edit at 03/11/2006 07:14AM

How To Switch Users
I tryed my sql manual and could not find a solution to my problem.

when i open mysql command line client 5.x it prompts for root password and when supplied i loged in sucessfully. that is ok.

my question is how to login as a diffrent user from mysql prompt?

assume currently i have loged in as root and wanted to login as xyz.

How To Select All Users?
How do i get all the users that are listed in my database to show up in a table?

Would it be something like ?

<?php SELECT username, id FROM 'users' WHERE rank by 'id' ?>

How would I do that? and how would I make it into a table?

List All Users
I'm running through a book on mySQL and have messed up adding users. I've got everything sorted now, but I want to clean up all the screwed up ones I've entered along the way. The only problem is I can't remember what I typed, so don't know what to delete. Is there a way of listing all the users, so I can pull off the ones I don't need?

Merge Users
im completly new to mysql and have not really touched it before.
i have a gaming website running php fusion, i have a main site and several other subsites (one for each game played) what i want is once someone registers on the top site they are registered on all the sites, php fusion isnt yet able to do this so i thought maybe i could do it in mysql, is it possible to have 2 or more tables that will always be the same apart from the names? ie main_user and bf2_user both with the same info in? either this or can you assign more than one name to the same table?

How To Create Users On A Mac?
I have installed MySql on my Mac, running Mac OSX 10.4

MySql is started automatically on system startup, and I can see the
"MySql" icon in the system preferences. So far, everything should run
normally.

Now how can I administrate, in order to specify users? From the
readme file, I concluded that by default, the at least a user
"mysql" should be initially defined with empty password, but when
I enter on the bash command line

mysql -u mysql

I get the error message

'Access denied for user 'mysql'@'localhost' (using password: NO)'

Users And Hosts?
Can someone answer a few questions:

Some background:

Host table has 0 entries
User table has:
+-----------+------+
| Host | User |
+-----------+------+
| localhost | |
| % | |
| localhost | mike |
+-----------+------+

I thought I deleted the root, but the Processes shows :
+----+------+----------------+--------+---------+------+--------+-----------
------------+
| Id | User | Host | db | Command | Time | State | Info
|
+----+------+----------------+--------+---------+------+--------+-----------
------------+
| 15 | root | 127.0.0.1:1254 | mysql | Sleep | 243 | | [NULL]
|
| 27 | root | 127.0.0.1:1296 | [NULL] | Query | 0 | [NULL] | SHOW FULL
PROCESSLIST |
+----+------+----------------+--------+---------+------+--------+-----------
------------+

1. If there are no hosts than how can the user table have hosts?
2 If there is no root than why is the always one connected even after a
restart?
3. Whats a blank username?
4. Who is @%?

Users And Hosts
Can someone answer a few questions:

Some background:

Host table has 0 entries
User table has:
+-----------+------+
| Host | User |
+-----------+------+
| localhost | |
| % | |
| localhost | mike |
+-----------+------+

I thought I deleted the root, but the Processes shows :
+----+------+----------------+--------+---------+------+--------+-----------
------------+
| Id | User | Host | db | Command | Time | State | Info
|
+----+------+----------------+--------+---------+------+--------+-----------
------------+
| 15 | root | 127.0.0.1:1254 | mysql | Sleep | 243 | | [NULL]
|
| 27 | root | 127.0.0.1:1296 | [NULL] | Query | 0 | [NULL] | SHOW FULL
PROCESSLIST |
+----+------+----------------+--------+---------+------+--------+-----------
------------+

1. If there are no hosts than how can the user table have hosts?
2 If there is no root than why is the always one connected even after a
restart?
3. Whats a blank username?
4. Who is @%?

Users Privilege
i noticed that when i connect to MySQL with php using:

mysql_connect();
or:
mysql_connect("dbhost", "dbusername", "dbpassword");

always will be connected and the user can do anything like creating databases or delete.
how can i prevent it? i just want the root user can do it.

Can't Log In B/c Deleted All Users
I installed the mysql-administrator GUI admin program, and my first task was to make it more secure by disabling anonymous logins and deleting/changing root access. I used the mysql-administrator to delete all accounts, and my goal was to then add another admin account right after, but mysql-administrator crashed on me and had a seg fault for some reason.

Now I don't seem to have any login ability as all users are gone. I've found articles online that speak of changing the root password, but I can't even log in as root or any other user (anonymous, included), so how do I get in? Luckily, I just started playing with mysql and have no valuable data. I'm running Fedora Core 4, and did a 'yum remove' of mysql and mysql-server. Then did a 'yum install' of both of tham again.

The problem is it's still acting like the old install (still looking for old config/password files of the old install??). Can someone tell me how to change/add users or completely remove mysql/d, and install again?

Removing Users
I can't seem to figure out how to remove users with php. I tried to do it with this
$query = mysql_query("REVOKE ALL PRIVILEGES, GRANT OPTION FROM user");

Where user is the name of the user I want to delete. That's what it said to do in the GRANT/REVOKE syntax part of the site but it doesnt do anything when I run the script.

Creating New Users
I have added a new user to the mysql.user table and gave it the same permissions as the 'root' user (all Y's in the database).

When I use these details in an asp connection string I get the following error:

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[MySQL][ODBC 3.51 Driver]Access denied for user 'nmssiteuser'@'localhost' (using password: YES)

Adding New Users
I can't seem to add a new user to my database! I've tried it through phpMyAdmin (under privileges) and also running the query

GRANT ALL PRIVILEGES ON *.* TO 'myusername'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION

which returned no errors and according to phpMyAdmin the user is entered into the `users` table. But when I try to login with that name I get

Access denied for user: 'myusername@localhost' (Using password: YES)

So all I can use to login is 'root' with no password. Not very secure!

DB Design Users
If you have a database with several table and u want users to access the information. What is the available methods to allow these users to access information ( READING and ADDING at least).

Do I add users like the root. Or creating table which hold users informations in which case I wonder how these users access data without mysql user???

No Users In Mysql
I am in the process of setting up a 'testing server' using IIS, PHP, MySQL etc. The server is up and running and PHP is working fine. I have installed MySQL 4.1.12a and the server is up and running, I have managed to connect to the 'mysql' db through the console without any problems.

However, when I installed phpMyAdmin I got the 'client does not support authentication' error message. I have found this in the manual and understand how to deal with it, but on closer inspection there are no users listed within the user table in 'mysql'. As far as I am aware there should be some default users with a new install??

How do I setup a couple of new users and ensure that phpMyAdmin can access the server etc?

Current Users
How can I check what are the current users right now (except for the admin)?
I can't find this in a manual.

Setting Up Users
I have a website and db where people can login get setup and then enter information into the db, everybody has a unique client number, can I create a user for the db when they set themselves up as a user and restrict them from changing anything except data that is connected to their client number?

Users And Permission
Being that no user is accepted from the command line (even root)
using the command:

mysql -u root

does anyone know if editing the 'users' database in /var/log/mysql
with vi would help?

Listing Users
I would like to list the users and their permissions on my MySQL server.

None Of Users Privileges
I have no privileges anymore to create a database or view privileges and users. Does somebody know how I can add a user or give my root all privileges again?

Adding Users
I can add users but how do I make it so the users can not see all the DB, I know I can restrict the user so they cannot veiw the data but I dont want them to even see the other DB's

ADDING NEW USERS
I have set up a linux machine running ubuntu. I finally was able to login to mysql with root, but I am unable to add other users. I use this command

mysql> grant select, insert, update, delete, index, alter, create, drop
-> on books.*
-> to bookorama identified by 'bookorama123';

and the response I get is:

QUERY OK 0 ROWS affected

I have no clue as to what is wrong. I tried logging into the user I thought I created, but it acts like it's not there.

List All Users
im trying to make a activity list that list all users who havent logged in in the last 60 days

i have the following code but it wont only list the last 60 days activity....

SELECT * FROM hq_user
WHERE user_currentvisit < (CURRENT_TIMESTAMP() - INTERVAL 60 DAY);
ORDER BY user_currentvisit ASC;

Creating Users
I've been having a little trouble creating users cross-platform. I have
a little script that works just fine on Solaris 8 using this command:

eval "/path/to/mysql --user=root --password=*****
--socket=/path/to/socket --database=mysql --execute="INSERT INTO user
(Host, User, Password, Select_priv, Insert_priv, Update_priv,
Delete_priv, Shutdown_priv, File_priv, Create_tmp_table_priv,
Lock_tables_priv) VALUES ('localhost', 'LocalUser', PASSWORD('******'),
'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y')""

With the obvious changes to make the statement actually work. However,
if I move this over to Linux, I get Invalid Authorization Specification
errors when I try to connect as LocalUser after a reload, and using
GRANT seems never actually to grant privileges (e.g. no "Y"s in the user
table). Does anybody know how I can successfully create a user with my
script?

Finding Users
ive got 2 tables, one of users and one of orders created by those users. The orders keep track of the user_id. I am looking to get a list of users who have not placed an order, or in other words, users who do not have their user_id in the order table.

Users And Privileges
I just installed mysql and was testing to see if i could setup privileges, now I am logged in as root using the mysql console and wanted to create a user and also give them some privileges..
I am using

mysql> GRANT SELECT,INSERT,UPDATE
-> ON *.*
-> TO bro@localhost
-> IDENTIFIED BY 'bobo';

mysql doesn`t give me an error or anything so i figured that it accepted it, but when i try to login using this new user it seems as if its now there. now i used phpMyAdmin to login using root then went to look at privileges and I donb`t see the new user anywhere..
I guess i did something wrong somewhere, any ideas on what it was? abit lost as im new and just following an ebook on this stuff

Registered Users
I have a simple bit of mysql to display the number of users on my service, by simply selecting the highest userid from the database.

"SELECT MAX(id) FROM users";

It would appear that i have not thought this through correctly, as when a user is deleted from the database, it still shows the number of registered users as being the same.
Is there an easy way to cound the number of registered users, without affecting performance too much?

Users Without Entries
Note that I'm using mysql 3....ugh.
I have a table containing users, primary key is 'id'
Another table contains their activities on a specific day
What I want to find is all users who have not entered an activity between 2 dates.
Basically the problem is that I don't know how to join 1 table along only non-existant rows of another.

Users And Trucks
I have 2 tables users and trucks. In the trucks I have a field that stores the users id.
I want to make a query that will give my all the trucks which users id doesn't exist in the table users. So if you know how this query should look like please respond.

This query gives me the total opppsite of what I want.
SELECT * FROM users, trucks WHERE truck_user=user_id

Delete All Users
I want to delete all users in my db with the userid between 10 and 20. But the following sql code wont let me.

delete * from nn_users
where userid
between (10 and 20);

Copying Users From One Database To Another
I have a database on my clients hosting server, and I want to set up these exact users on my MySQL instance on my local PC. How can I do this? Or how can I see the permissions set for each user so that I can create them from new and set the relevant priviliges?

Grab All Users Not In Second Table.
I have two tables. I want to grab all the users from the users table who are not found in the second table. It's just seems to be one of those days where I can't perform the simple tasks, I think I need to go back to bed.

[table] users
[field] userid

[table] user_details
[field] userid

Select userid from users where userid not in user details

Best Way To Track Online Users?
I'm currently using a custom-made login class that basically sends a REPLACE INTO online_user SET id=$userid every time a page with a registered session is loaded

Adding Users In Phpmyadmin
Why is it always so difficult to create new mysql users? I just can't get the hang of it, whatever I method I follow from the mysql.com website just doesn't work.

I am running mysql 4.1.20 can someone please tell me how I can create new users?


Copyright © 2005-08 www.BigResource.com, All rights reserved