Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8302269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:14:43+00:00 2026-06-08T17:14:43+00:00

Im making a browser mafia game, and coding the page where it lists all

  • 0

Im making a browser mafia game, and coding the page where it lists all of the familys / gangs.

Each family has a points rating, made up of the combined SUMs of all its members cash, bullets, exp, etc.

This is my code to loop through to show the family listings:

SELECT 
 (SELECT COUNT(*) FROM players WHERE status='alive' AND family=f.id) as member_count,
 (SELECT SUM(bullets) FROM players WHERE status='alive' AND family=f.id) as sum_bullets,
 (SELECT SUM(cash) FROM players WHERE status='alive' AND family=f.id) as sum_cash,
 (SELECT SUM(exp) FROM players WHERE status='alive' AND family=f.id) as sum_exp,
 (SELECT SUM(killscore) FROM players WHERE status='alive' AND family=f.id) as sum_ks,
 name, id FROM familys f

then during the loop with PHP I work out the total points:

$points = $rs[sum_bullets]/500;
$points = $points + $rs[sum_cash]/10000;
$points = $points + $rs[sum_exp]/1000;
$points = $points + $rs[sum_ks];

Now onto the question. I want to order the results using ORDER BY points DESC. How can I adjust my query to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:14:44+00:00Added an answer on June 8, 2026 at 5:14 pm

    try to shift logic from application to MySQL to make it faster with a single query as:

    SELECT
        (SELECT COUNT(*) FROM players WHERE status='alive' AND family=f.id) as member_count,
        (SELECT SUM(bullets) FROM players WHERE status='alive' AND family=f.id) as sum_bullets,
        (SELECT SUM(cash) FROM players WHERE status='alive' AND family=f.id) as sum_cash,
        (SELECT SUM(exp) FROM players WHERE status='alive' AND family=f.id) as sum_exp,
        (SELECT SUM(killscore) FROM players WHERE status='alive' AND family=f.id) as sum_ks,
        name, id
    FROM familys f
    ORDER BY (sum_bullets/500 + sum_cash/10000 + sum_exp/1000 + sum_ks);
    

    Edit: for output of total_points

    SELECT a.*, (sum_bullets/500 + sum_cash/10000 + sum_exp/1000 + sum_ks) AS total_points
    FROM
        (
         SELECT
            (SELECT COUNT(*) FROM players WHERE status='alive' AND family=f.id) as member_count,
            (SELECT SUM(bullets) FROM players WHERE status='alive' AND family=f.id) as sum_bullets,
            (SELECT SUM(cash) FROM players WHERE status='alive' AND family=f.id) as sum_cash,
            (SELECT SUM(exp) FROM players WHERE status='alive' AND family=f.id) as sum_exp,
            (SELECT SUM(killscore) FROM players WHERE status='alive' AND family=f.id) as sum_ks,
            name, id
         FROM familys f
        ) a
    ORDER BY (sum_bullets/500 + sum_cash/10000 + sum_exp/1000 + sum_ks) ASC;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a javascript game but (not browser-based) but the engine I'm using has
so I am making a browser based game using raphael v2 to serve up
im making some script with mechanize.browser module. one of problem is all other thing
I've been on and off intrested in making a text based browser game. I
I'm making a browser bug archive application and for each bug I want to
I am making a browser based javascript game. As such, within the game there
I'm making a browser based game which involves a map. To render the map
Some code in my page is making my browser slow after 20-30 min. I
I'm making a web browser based multiplayer game. I've determined that websockets are the
I'm in the process of making a browser based multiplayer turnbased strategy game similiar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.