Criss Criss - 2 years ago 71
SQL Question

How can I select all id's from a sql table in descending order and then echo them (in php)?

I have several id's in a table called "leaderboards" that belong to different users. They're named as:"id_user" and they're not in order. What I want to do is printing divs in a leaderbord which should contain some info that I get from those id_user's.

The only problem I have about it is that after a research on stackoverflow and other websites, I still couldn't find how to select those id_user's in descending order AND be able to take one by one to get the info from that user and then continue with the next id_user, and so on.

I don't know how to select the specific row of each id_user in descending order to do the other codes that I already know how to do.

I hope it's not a duplicate of any other previosly asked question on this website (I really did a research and I couldn't find any specific answer to this question, for the sql part and the php part all together).

Thank you so so much beforehand.

Answer Source

You could do with a good read up on both PHP and MySql but I'll give you a clue.

// The SQL You need

SELECT * FROM `the_name_of_your_table` ORDER BY `user_id` DESC;";

//The PHP

foreach($Sql_result AS $result){

  print $result['foo'] . " - " . $result['bar'] . "<BR>";

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download