baxt01 Posted October 17, 2016 Share Posted October 17, 2016 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 comment Share on other sites More sharing options...
dsonesuk Posted October 17, 2016 Share Posted October 17, 2016 Use 'ORDER BY' http://www.w3schools.com/sql/sql_orderby.asp 1 Link to comment Share on other sites More sharing options...
baxt01 Posted October 17, 2016 Author Share Posted October 17, 2016 spot on I was trying to do it after the SELECT statement using PHP lol Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now