Jump to content

Recommended Posts

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);

?>

Link to comment
https://forums.phpfreaks.com/topic/271235-sorting-loaded-tables/
Share on other sites

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!!

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.