Jump to content

how to sort() my data output from my DB SELECT


Recommended Posts

Hi I have been working on building a custom post a result set to a database which thankfully I have now managed with some help,

now I am working on the other end of this project the displaying the saved data back to users,

From the start of this I have an online tournament hosting group that go to my form and post a list of player names with points earned per tournament.

Once the form is submitted it's sent to my form_processing.php where the results are exploded and split into 2 arrays "$player_name, $points"

Then on the INSERT I have an INSERT

$sql = "INSERT into `bg_points` (`player_name`, `points`) values (?, ?)
                on duplicate key update points = points + ?";

to of course update current player points if the exist or add new records if not.

Then finally saved into my DB table,

 

now I am working on building the page to display these points back to the players so they can track their earned points and standings each month.

which is easy enough I just call an MySQL SELECT * FROM statement on the DB table that's done,

Now I need to sort these results in lowest to highest order by points

so if

player1 has 120 points

player2 has 50 points

player3 has 75 points

 

player4 has 5 points

 

then I need to be displaying these back as

player4

player2

player3

player1

 

I have had a look online for some possible examples to help guide me into this and I either get HTTP 500 or just no effect at all.

here is the very basic code I have put together so far which I can and will update and add into my site framework once I have it in order and working...

<HTML>
<head></head>
<body bgcolor="#0000FF">
<?PHP
$servername = "localhost";
$username = "***********";
$password = "*******";
$dbname = "***********";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

	
	//output the saved data 
		$sql = "SELECT * FROM `bg_points` ";
		$result = $conn->query($sql);
		

		if ($result->num_rows > 0) {
			// output data of each row
			while($row = $result->fetch_assoc()) {
				echo "id: " . $row["id"]. "   $nbsp   $nbsp Playerv Name: " . $row["player_name"]. "   $nbsp   $nbsp Points: " . $row["points"]. "<br>";
			}
		} else {
			echo "0 results";
		}
 $conn->close();
?>

</body>
</html>

thanks for any help or ideas in advanced

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...