hahaitwork Posted November 27, 2012 Share Posted November 27, 2012 Hello, I'm loading data from my database but now I need them sorted as well, after "score". I need the highest score to be on the top, and let's say it shows a total of 50. that means if someone have 100 score, and rest is 99-10 and the last is 1.. I want 100 on top, 1 on buttom and 99-10 between.. bet you understood it Any ideas? my script is this so far: <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM members"); echo "<table border='1'> <tr> <th>Name</th> <th>Score</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['score'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/271235-sorting-loaded-tables/ Share on other sites More sharing options...
Muddy_Funster Posted November 27, 2012 Share Posted November 27, 2012 change your query to this : SELECT name, score FROM members ORDER BY name ASC, score DESC asssming you primarily want to alphabetize your members first and then order by score, if you just want to purely order by score alone then just use SELECT name, score FROM members ORDER BY score DESC and PLEASE use code tags!! Quote Link to comment https://forums.phpfreaks.com/topic/271235-sorting-loaded-tables/#findComment-1395449 Share on other sites More sharing options...
hahaitwork Posted November 27, 2012 Author Share Posted November 27, 2012 change your query to this : SELECT name, score FROM members ORDER BY name ASC, score DESC asssming you primarily want to alphabetize your members first and then order by score, if you just want to purely order by score alone then just use SELECT name, score FROM members ORDER BY score DESC and PLEASE use code tags!! Thanks I did find a script to sort it actually but it sorted the wrong way so thanks for your script! ehm, true.. sry I forgot about the code tags. Quote Link to comment https://forums.phpfreaks.com/topic/271235-sorting-loaded-tables/#findComment-1395452 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.