Pulling and sorting MySQL data
Posted: Sun Dec 18, 2005 2:26 pm
I decided to post this here instead of the databases section because I think the solution requires more PHP than MySQL. Basically, I want to pull data from one table and organize it using the data from another table. I have a table called users which holds all the info about every user of my site. I also have a table called favourites which is basically two columns: user_id and fav_id. The person is fav_id is one user_id's favourites list. If I am pulling all the info about a user,I also want to pullhis favourites list, so I use the following code:
The complication comes from the fact that every user on the site has a popuarity. When I pull the favourites for a given user, I want the 10 most popular users shown first. How can I do this? Is there a query that can do itfor me?
Thanks.
Code: Select all
mysql_query("SELECT * FROM `favourites` WHERE `user_id` = $this->userid", $this->db);Thanks.