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 9225983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:42:57+00:00 2026-06-18T04:42:57+00:00

I have a problem in sorting table from information took from SQL database. I

  • 0

I have a problem in sorting table from information took from SQL database. I need to sort the table with PHP variable $points (which is count from two different fields in SQL database and printed as last part of the table so the points IS NOT included in SQL).

So basically I need to sort the table by $points without saving any information about points directly to the SQL database.

I wonder what would be the simplest way to do it if it is possible?

And the PHP code is down here:

if(isset($_REQUEST['button'])) {
    $connect = mysqli_connect("localhost","root","","Points_database");
    if (mysqli_connect_errno()) {
        echo "Error: ", mysqli_connect_error();
        exit();
    }
    $sql = "SELECT * FROM Points_table;";
    $query = mysqli_query($connect,$sql);
    echo "<table><tr><td>Team</td><td>Games</td><td>Wins</td><td>Tie</td><td>Losses</td><td>Goals</td><td>Points</td></tr>";
    $rowcount=0;
    while($row = mysqli_fetch_array($query,MYSQL_ASSOC)) {
        $rowcount++;
        $points= $row['wins'] * 3 + $row['tie'];
        if($rowcount%2==0) {
            echo "<tr class='rowstyle2'>";
        }
        else {
            echo "<tr>"; 
        }
        echo "<td>".$row['team']."</td><td>".$row['games']."</td><td>".$row['wins']."</td><td>".$row['tie']."</td><td>".$row['losses']."</td><td>".$row['goals']."</td><td>".$points."</td></tr>";
    }
    echo "</table>";
}
  • 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-18T04:43:00+00:00Added an answer on June 18, 2026 at 4:43 am

    why not?

    SELECT *, (wins*3 + tie) AS pts FROM table ORDER BY pts DESC
    

    or if you dont want calculations in SQL

    SELECT * FROM table ORDER BY wins*3 + tie DESC
    

    here it is: http://sqlfiddle.com/#!2/d2045/4

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with sorting items in table in PHP. Here is what
I have a complex sorting problem with my SQL statement. I have a table
I have a problem with sorting... I need to sort NSArray containing NSDictionaries .
My setup: I have a sqlite database from which I populate a NSMutableArray of
I am having a problem sorting results from joining tables that have to be
I have a problem with sorting NSTableColumn contents. In my NSTableView there are three
I have a problem on using LinqToSQL with paging + dynamic sorting. These are
I have a JSF page that displays a table from an object called TableQuery
I have a problem with Gridview sorting that is similar to others but I'm
I have a complex table pulled from a multi-ActiveRecord object array. This listing is

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.