Adjacency Matrix in php -- vlookup in Excel

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
PHP_mySQL__Newbie
Forum Commoner
Posts: 29
Joined: Fri Aug 12, 2011 5:40 pm

Adjacency Matrix in php -- vlookup in Excel

Post by PHP_mySQL__Newbie »

My actual data has 100 x-values ( x1, x2, .... x100)
and 2000 s-values (s1, s2, ...... s2000)

Question 1: Which sites were visited by at least 2 people?
Question 2: How may people visited at least 2 sites?

Problem:
5 people (x1, x2, x3, x4, x5) visited some of the 7 possible sites (s1, s2, s3, s4, s5, s6, s7)
Sample Input:
x1, s1
x2, s3
x1, s3
x3, s7
x1, s7
x5, s2
x5, s1
x5, s3

Desired Output#1: List of sites visited by at least 2 people

Code: Select all

Sites, #times, list of people
s1,         2, (x1, x5)
s3,         3, (x1, x2, x5)
Desired Output#2: List of people who visited at least 2 sites

Code: Select all

People, #times, sites
x1,         3, (s1, s3, s7)
x5,         3, (s1, s2, s3)
1) Any ideas where do I begin with?
2 Should I use an adjacency matrix?
3) Am I better off just working with Excel and use vlookup?
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Adjacency Matrix in php -- vlookup in Excel

Post by Eric! »

How is your data stored? I'm guessing:

Code: Select all

x['user_name']=array("site_name"); // array of all visited sites
s['site_name']=number_of_visits; // count of site hits
If your data is stored like this then you can either loop through the data or use some of the array sorting and key sorting functions to get what you want.
Post Reply