Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Script for registered users high score
Old 04-02-2010, 10:43 PM Script for registered users high score
Junior Talker

Posts: 3
Name: Tommy
Trades: 0
Hi, I have MySQL with a database of registered users.

Now I want to make a script where the users click on a certain link, and they'll get a point. For every time they click this link they will add one more point to their existing score.

After that I want to make a table that displays the 10 top scores of all the users.

How do I go about this?

Thanks
moltar is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-03-2010, 06:14 AM Re: Script for registered users high score
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
If you don't know how to write it. ...
















... Hire somebody
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-03-2010, 11:50 AM Problem with ranking users
Junior Talker

Posts: 3
Name: Tommy
Trades: 0
Hi, I want to rank my users for a high score.

I tried putting this query in MySQL:

Code:
$sql = 'SELECT * FROM users ORDER BY points DESC, username ASC LIMIT 20';
but got this reply:

Code:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$sql = 'SELECT * FROM users ORDER BY points DESC, username ASC LIMIT 20'' at line 1
What have I done wrong? the table is called users and there is username and points in it.

Also, I've tested a few other queries with success, but I don't know how to actually show the ranking in a .php page. And I've looked everywhere and can't get an explanation of this.

Thanks
moltar is offline
Reply With Quote
View Public Profile
 
Old 04-03-2010, 12:18 PM Re: Script for registered users high score
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
A php string is NOT a SQL query.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-03-2010, 12:27 PM Problem with users ranking
Junior Talker

Posts: 3
Name: Tommy
Trades: 0
I'm very new to php and I hope this thread doesn't get locked aswell. I'm making a highscore table that will display my users in order of highest points. I've entered a query which seems to work, but the question still remains, where should I put it to display the information on a php page? I've tried putting it in a td table in <?php but it just shows an empty table.

Code:
SELECT
  ID, username, points,
  @prev := @curr,
  @curr := points,
  @rank := IF(@prev = @curr, @rank, @rank+1) AS rank
FROM
  users,
  (SELECT @curr := null, @prev := null, @rank := 0) sel1
ORDER BY points DESC
;
Thanks for any help!

of course, the php coding of it would be:

Code:
$sql  = 'SELECT'
        . '   ID, username, points,'
        . '   @prev := @curr,'
        . '   @curr := points,'
        . '   @rank := IF(@prev = @curr, @rank, @rank+1) AS rank'
        . ' FROM'
        . '   users,'
        . '   (SELECT @curr := null, @prev := null, @rank := 0) sel1'
        . ' ORDER BY points DESC'
        . ' ;  LIMIT 0, 30 ';

Last edited by moltar; 04-03-2010 at 12:29 PM..
moltar is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Script for registered users high score
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.31978 seconds with 12 queries