Link to home
Start Free TrialLog in
Avatar of mfuerlinger
mfuerlinger

asked on

mysql_query ORDER BY most existing rows

I am administrating a little webshop built in php/mysql where users can choose from a list of items and send a request about the item they like.
Everything works fine.  But now I want to have this content list sorted after the number of the most requested items (all requests are stored in table2)

details:
I have the two existing sql tables ("content" and "request_log")

table1 "content"
==========
this table contains a long list of content offered for requests from the net. It contains the following columns: "unique_id", "name", "description", ....

table1 looks like: for example:
"767","porsche911","red, good condition fast"
"893","mercedes","silver 5 years old"
"613","lexus","gold 5 doors"



table2 "request_log"
=============
the second table is used as a request table. The rows are updated dynamically after any request of the content of table1.
It contains the following columns "unique_id", "date", "requestemail", ... (unique_id of table2 corresponds with unique_id of table1).

table2 looks like: for example:
"893","23.06.2006","wanttobuymercedes@yahoo.com"
"893","21.06.2006","requestformercedes@yahoo.com"
"893","18.12.2005","mercedesrequest@hotmail.com"
"767","23.07.2005","like_porsche@gmx.com"


Normaly table1 is shown and sorted by random.
with this cmd: $sql = mysql_query(" SELECT * FROM $tabname ORDER BY rand() ");
Now I want to sort table1 after number of requests. The result should be a sorted list of the most requested content.

output should look like this:
1.) The car mercedes with ID 893 was requested 3 times
2.) The car porsche911 with ID 767 was requested 1 time
3.) The car lexus with ID 613 was requested 0 time

I am a php newbie. php.net and EE could not help me so far. And please explain your code. ;-)

Hope someone can help me. Many thanks in advance

Mathias



ASKER CERTIFIED SOLUTION
Avatar of Autogard
Autogard

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial