Having tried several possibilities I have come to a stop. Without overloading the mysql server with hundreds of queries, this is what I am trying to achieve:
Here is the table
CREATE TABLE `users` (
`id` int(11) NOT NULL auto_increment,
`firstname` varchar(64) NOT NULL,
`lastname` varchar(64) NOT NULL,
`email` varchar(64) NOT NULL,
`status` smallint(5) NOT NULL,
`refchid1` int(11) NOT NULL,
`refchid2` int(11) NOT NULL,
`refchid3` int(11) NOT NULL,
`refchid4` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;
Explanation:
- I am trying to adjust a person’s status based on a complex tree. Each user has an id as denoted by the auto_increment id field.
- User A has his details entered into the table.
- User B is refered by User A, so when his details are entered refchid1 has the same id as User A.
- User C is refered by User B, his refchid1 becomes the id of User B and his refchid2 becomes the id of User A.
- User D is refered by User C, his refchid1 becomes that of User C, refchid2 that of UserB and refchid3 that of User A.
If you understand the referencing of the above, you are on the right track.
Sample Data of above description:
(6, 'Lars', 'Luna', 'Morbi.non.sapien@enimgravida.com', 25, 0, 0, 0, 0),
(7, 'Sonya', 'Cox', 'tellus@orci.org', 25, 6, 0, 0, 0),
(8, 'Aiko', 'Hodge', 'vestibulum.neque.sed@vel.edu', 25, 7, 6, 0, 0),
(9, 'Lillith', 'Bray', 'purus.Duis.elementum@necurnasuscipit.org', 25, 8, 7, 6, 0),
(10, 'Macey', 'Hayes', 'mi.pede@aliquetodioEtiam.net', 25, 9, 8, 7, 6);
What I am trying to accomplish is this:
- The default status is 25. (25,28,30,35,40) See this basically as a discount system, where the more people you refer and the more people they refer where you where the originating referer, you receive larger discounts.
- If User A has at least 10 unique users he has referenced as refchid1 he gains status.
- If User A has at least 10 uniuque users in refchid1 that each in turn has 10 unique users in refchid1 where User A is refchid2, he gains status.
- User A has 10 unique users in rechid1 that each have 10 unique users in refchid1 where user A is rechid2 that in turn have 10 unique users in refchid1 where user A is refchid3.
- etc.
As stated, the structure of testing is complex and I wish to do this without overloading the mysql server with millions of queries. The query should be an UPDATE query that will adjust the status of all matching users.
Does anyone have a solution of how I am going to accomplish this?
i should have created a list of user, and a seperate table for references,
and when you add a new user, if that user was refered by another user, add one row whit depth 1,
then select all references linked to that user and add depth whit 1:
and then to calculate points