tags:

views:

34

answers:

1

How can i create a section on my website where i show the 5 most viewed items? I guess it's a start to use this query: SELECT TOP 5 * FROM Palace. But how can i detect the number of views and link it to the right palace?

Doing the echo afterwards shouldn't give that much trouble.

Thnx in advance!

A: 

I assume you have:

  1. A table with the number of visits for each item called visits. This table will have 2 fields: item_id and num_visits
  2. A table with the items, called items. This will contain at least id, item_name and item_URL (if needed e.g. if you're coding nice URLs with mod_rewrite).

Then you'll do something on the lines of:

SELECT i.item_name, i.item_URL, v.num_visits 
   FROM visits v 
   LEFT JOIN items i ON v.id_item = i.id 
   ORDER BY v.num_visits DESC LIMIT 5 

Parse the results with PHP/ASP/whatever you're using to code your website and you're set!

nico
Thnx alot Nico! I'll try it out as soon as i have a minute!
Rypens