Jiraiya Posted November 23, 2008 Share Posted November 23, 2008 i was wondering how do i display a list of numbers from a database table from highest to lowest? Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/ Share on other sites More sharing options...
genericnumber1 Posted November 23, 2008 Share Posted November 23, 2008 the easiest way would be when you query just ordering by the number's column descending. Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696698 Share on other sites More sharing options...
Jiraiya Posted November 23, 2008 Author Share Posted November 23, 2008 what would that code look like if you dont mind please Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696703 Share on other sites More sharing options...
genericnumber1 Posted November 23, 2008 Share Posted November 23, 2008 assuming you want to retrieve all columns from a table named "table" with a column containing the numbers you wish to sort by named "numbers" SELECT * FROM table ORDER BY numbers DESC Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696712 Share on other sites More sharing options...
Jiraiya Posted November 23, 2008 Author Share Posted November 23, 2008 what if i only wanted to display certain parts of the table along with the variable that i need displayed from highest to lowest? Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696725 Share on other sites More sharing options...
genericnumber1 Posted November 23, 2008 Share Posted November 23, 2008 just add the where clause to the query......... SELECT * FROM table WHERE something='something' ORDER BY numbers DESC you might want to look up some sql tutorials to get the basics down. Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696732 Share on other sites More sharing options...
Jiraiya Posted November 23, 2008 Author Share Posted November 23, 2008 it didnt work this is the script i have mysql_select_db("members", $con); $result = mysql_query("SELECT * FROM users WHERE skill='skill' ORDER BY skill DESC"); echo "<table border='1'> <tr> <th>Name</th> <th>Rank</th> <th>Skill</th> <th>Kekkei Genkai</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['username'] . "</td>"; echo "<td>" . $row['rank'] . "</td>"; echo "<td>" . $row['skill'] . "</td>"; echo "<td>" . $row['bloodline'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696734 Share on other sites More sharing options...
genericnumber1 Posted November 23, 2008 Share Posted November 23, 2008 did you mean ORDER BY rank DESC? you pulled where skill='skill'... there's no reason to sort by a value when only one unique value exists. Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696737 Share on other sites More sharing options...
Jiraiya Posted November 23, 2008 Author Share Posted November 23, 2008 no i need it ordered by skill Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696739 Share on other sites More sharing options...
genericnumber1 Posted November 23, 2008 Share Posted November 23, 2008 ... you're using WHERE skill='skill' that means you're only retrieving values from the database where the value in the skill column is skill.... you then sort by skill.... all results have "skill" for the skill value because you specifically said those were the columns you wanted.... ... if you sort by skill where all values are skill there's no sorting to be done... ... I really can't help you if you can't understand the problem with the logic here. Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696744 Share on other sites More sharing options...
Jiraiya Posted November 23, 2008 Author Share Posted November 23, 2008 i understand the problem how do i fix it wanna display all the data that is listed below it but i need it to be ordered based on the skill variable Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696746 Share on other sites More sharing options...
genericnumber1 Posted November 23, 2008 Share Posted November 23, 2008 Why are you selecting all values where the column skill has "skill" for the value? Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696753 Share on other sites More sharing options...
Jiraiya Posted November 23, 2008 Author Share Posted November 23, 2008 im kinda new at this and i know my mistake im just not sure how to fix it Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696754 Share on other sites More sharing options...
Jiraiya Posted November 23, 2008 Author Share Posted November 23, 2008 should i replace 'skill' in skill='skill with the name of the table? that the data is in Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696762 Share on other sites More sharing options...
genericnumber1 Posted November 23, 2008 Share Posted November 23, 2008 How about this: tell me exactly what you want to retrieve from the table and I'll tell you the query to use. Then we can discuss why I suggested the query I did. Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696767 Share on other sites More sharing options...
Jiraiya Posted November 23, 2008 Author Share Posted November 23, 2008 i want to display this but i want to have it in order by highest to lowest based on the skill variable <th>Name</th> <th>Rank</th> <th>Skill</th> <th>Kekkei Genkai</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['username'] . "</td>"; echo "<td>" . $row['rank'] . "</td>"; echo "<td>" . $row['skill'] . "</td>"; echo "<td>" . $row['bloodline'] . "</td>"; echo "</tr>"; Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696776 Share on other sites More sharing options...
genericnumber1 Posted November 23, 2008 Share Posted November 23, 2008 Okay... let's try this one more time... give me 5 values from the table and tell me which values you wish to retrieve and in which order and I will tell you the query to use. Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696777 Share on other sites More sharing options...
Jiraiya Posted November 23, 2008 Author Share Posted November 23, 2008 theres just 4 variables i want to display they are username, rank ,skill and bloodline. i want it to be in order from highest skill to lowest skill Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696780 Share on other sites More sharing options...
genericnumber1 Posted November 23, 2008 Share Posted November 23, 2008 then just try SELECT * FROM users ORDER BY skill DESC Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696783 Share on other sites More sharing options...
Jiraiya Posted November 23, 2008 Author Share Posted November 23, 2008 i tried that the page came up blank mysql_select_db("members", $con); SELECT * FROM users ORDER BY skill DESC $result = mysql_query("SELECT * FROM users ORDER BY skill DESC"); echo "<table border='1'> <tr> <th>Name</th> <th>Rank</th> <th>Skill</th> <th>Kekkei Genkai</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['username'] . "</td>"; echo "<td>" . $row['rank'] . "</td>"; echo "<td>" . $row['skill'] . "</td>"; echo "<td>" . $row['bloodline'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696786 Share on other sites More sharing options...
genericnumber1 Posted November 23, 2008 Share Posted November 23, 2008 add error_reporting(E_ALL); to the top line of your script Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696791 Share on other sites More sharing options...
Jiraiya Posted November 23, 2008 Author Share Posted November 23, 2008 it still came up blank Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696796 Share on other sites More sharing options...
genericnumber1 Posted November 23, 2008 Share Posted November 23, 2008 When you say "blank" what do you mean? completely white or just no results? Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696797 Share on other sites More sharing options...
dropfaith Posted November 23, 2008 Share Posted November 23, 2008 <?php mysql_select_db("members", $con); $query = "SELECT * FROM users ORDER BY skill DESC"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); echo "<table border='1'> <tr> <th>Name</th> <th>Rank</th> <th>Skill</th> <th>Kekkei Genkai</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['username'] . "</td>"; echo "<td>" . $row['rank'] . "</td>"; echo "<td>" . $row['skill'] . "</td>"; echo "<td>" . $row['bloodline'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696804 Share on other sites More sharing options...
Jiraiya Posted November 23, 2008 Author Share Posted November 23, 2008 its coming up white Link to comment https://forums.phpfreaks.com/topic/133855-solved-math-ordering-numbers/#findComment-696822 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.