Here is how it works in mysql:
SELECT t2.page_name,Count(t2.page_name) AS popularity FROM mytable AS
LEFT JOIN mytable AS t2 ON t1.session_id = t2.session_id
WHERE t1.page_name = 'a'
AND t2.page_name <> 'a'
GROUP BY t2.page_name
ORDER BY Count(t2.page_name) DESC
where mytable is a list of unique combinations of session IDs and pages
e.g. a table with the following fields:
ID, session_id, page_name
where you can only have unique combos of session_id and page_names
The sql will give you a list of the five most popular pages for people who
visited page "a"
If you publish this list with links to these "also popular" pages, then you
need to exclude these visits from my_table, otherwise it becomes a
self-fulfilling prophecy. That is, once a page is popular, it will become
more popular because it is popular, etc....
People who visit many pages will have more influence on the "also popular"
list. However, the link for them between page a and b is less strong,
because there is also a link between page a and c, a and d, a and e, and so
on. While someone who only visits page a and b shows a clear link.
I am actually going to look at more than just page visits, I am going to
look at things like click-throughs to links from a page and email message as
these will be more meaningful than just page views.