cod3rShea
cod3rShea

Reputation: 15

MYSQL JOIN USING PHP

I'm currently working on building a text-based game. I've been able to create the signup and where the user can pick between three classes. The next part I'm working is on is having a ranking system. The ranking would order the users by username and by highest-lowest experience, based on the user class. I don't have much experience with JOINS and the query is not giving the desired results. Any help would be appreciated.

SELECT ux_users.id, ux_users.username, ux_users_power.experience 
FROM ux_users, ux_users_power 
WHERE user_class ='ninja' 
ORDER BY experience DESC 
LIMIT 5

Table One ux_users:

     id   |  username |   
------------------------
     1    |   zak     |
     2    |   mike    |
     3    |   john    |

Table Two ux_users_power:

     id   | experience|   user_class   
---------------------------------
     1    |     22    |     Ninja
     2    |     01    |     Ninja
     3    |     34    |     Pirate

Upvotes: 1

Views: 126

Answers (1)

O. Jones
O. Jones

Reputation: 108641

Take the plunge into the 21st century and use explicit JOIN operations in place of the old-timey comma join.

In your case, this should work.

FROM ux_users
JOIN ux_users_power 
     ON ux_users.id = ux_users_power.id

The ON clause indicates the criteria for matching rows from the tables on the two sides of the join.

This is based on my guess that your two tables' id values both identify the user.

Upvotes: 1

Related Questions