473,327 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

PHP Ranking System, how do I go about doing this?

I'm on a school assignment and I've ran into some trouble and is in need of some urgent help.

Expand|Select|Wrap|Line Numbers
  1. Table name: users
  2.  
  3. ID  |  username  |  score
  4. 1   |  member A  |  100
  5. 2   |  member B  |  200
  6. 3   |  member C  |  300
  7. 4   |  member D  |  0
  8.  
I want show the top 3 members by their score in descending order in PHP.

My sql query for this would be

Expand|Select|Wrap|Line Numbers
  1. SELECT username, score FROM users ORDER BY score DESC LIMIT 0,3
  2.  
I'd like it to be in a simple format like below

Rank: 1 / User: member C / Score: 300
Rank: 2 / User: member B / Score: 200
Rank: 3 / User: member A / Score: 100

I've gotten this much so far, could anyone help me with the PHP part and how to echo it out?
Jan 14 '10 #1
3 3428
Dormilich
8,658 Expert Mod 8TB
check out mysql_query(), this should get you started.
Jan 14 '10 #2
Markus
6,050 Expert 4TB
How is the data stored? MySQL? MSSQL? Flat-file?
Jan 14 '10 #3
It's stored inside MySQL. But I've got it figured out already.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. //mysql connection stuff
  4.  
  5. $query1=mysql_query("SELECT * FROM users ORDER BY score DESC LIMIT 0,5");
  6.             echo "<table border='0'>
  7.             <tr>
  8.             <td><b><div align='left'></div>User</b></td><td>&nbsp;</td>
  9.             <td><b>Score</b></td>
  10.             </tr>";
  11.  
  12.             while($row = mysql_fetch_array($query1))
  13.               {
  14.               echo "<tr>";
  15.               echo "<td><div align=left>" . $row['username'] . "</div></td><td>&nbsp;</td>";
  16.               echo "<td><div align=center>" . $row['score'] . "</div></td>";
  17.               echo "</tr>";
  18.               }
  19.             echo "</table>&nbsp;&nbsp;";
  20.  
  21.  
  22. ?>
  23.  
  24.  
Jan 15 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Petre Huile | last post by:
I have designed a site for a client, but they have hired an internet marketing person to incrase their search engine ranking and traffic. He wants to put extra-large fonts on every page which will...
5
by: ED | last post by:
I currently have vba code that ranks employees based on their average job time ordered by their region, zone, and job code. I currently have vba code that will cycle through a query and ranks each...
1
by: Joseph Bloch | last post by:
In all the threads on ranking in Access queries, I've not seen anything that deals with ranking against a subset of the query results. What I need to do is take the following query results: Dept...
6
by: sara | last post by:
I hope someone can help with this. Our director wants to have a report that will have the departments (Retail stores) across the top, stores down the side and the RANKING of the YTD dept sales...
8
by: AnndieMac | last post by:
I have an Access 2002 database of inventory count results, and I have been asked to create summaries of the items with the most losses at a store, region and national level. Individually, I have been...
1
by: enpsycho | last post by:
Hi, 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...
0
debasisdas
by: debasisdas | last post by:
Rank:-assigns A Unique Number For Each Row Starting With 1,except For Rows That Have Duplicate Values,in Which Case The Same Ranking Is Assigned And A Gap Appears In The Sequence For Each Duplicate...
1
by: Paulo | last post by:
Hi, I need to create a ranking column wich will be the row number... it is the seller wich most sells... Ranking Seller Sum 1 Paul 2.212,00 2 Robert ...
0
by: Maciej Gawinecki | last post by:
Hello, Recently I've interested in quering XML document streams. They can be queried in keyword- based manner (non-structural queries), as the authors of the article "Semantic Search over XML...
3
TheServant
by: TheServant | last post by:
Hey guys, Here is my situation: I want to make a ranking system, which will rank users on their points. However the catch is, it should only be updated every 10 or 20 minutes so that ther is no...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.