markalanbaker Posted May 6, 2011 Share Posted May 6, 2011 I have an idea and I'm wondering if this would be possible in PHP (probably tied to a MySQL database). Just trying to figure out if the logic would work and if PHP could accomplish something like this. If I had a database filled with say 1000 universities. Each university had 10 values (student body size, number of majors, on campus housing availability, etc...) and each of these values was scored 1 through 10 with 10 being high. And then a prospective student answered 10 questions (what kind of student body size would you like, Do you want lots of options for majors, Do you want housing on campus... Would it be possible in PHP to write some code that would save the students 10 answers and then compare these answers against the 1000 schools and find the best match? I'm thinking it would need to give each value for each school a "score" and then total the 10 value scores into 1 grad total score. A few of the first questions would be filters basically before getting to the value rated questions. So, an example might be Do you want to go to school on the east coast? If they say yes, then all the schools that are not on th east coast should be excluded from the comparison of the values for remainder of the questions. Sound possible? Thanks! Mark Quote Link to comment https://forums.phpfreaks.com/topic/235696-is-this-possible-in-php/ Share on other sites More sharing options...
Adam Posted May 6, 2011 Share Posted May 6, 2011 Very possible. Though asking them to enter 1-10 for the question "what kind of student body size would you like?" doesn't sound right. Would you replace the 1-10 values with textual representiations; 1 - very small, 2 - small, 3 - kind of small, 4 - .. etc. ? Quote Link to comment https://forums.phpfreaks.com/topic/235696-is-this-possible-in-php/#findComment-1211429 Share on other sites More sharing options...
markalanbaker Posted May 6, 2011 Author Share Posted May 6, 2011 Yes, I probably would use something more user friendly than numbers. Good thought. Thanks for letting me know it is possible. Do you think this is reasonable in terms of coding? In other words, is this going to require a ridiculous number of variables to make happen? What I am thinking is that each school would have a score for each question. When I input the schools into the database I would give them each a score (1-10) for each field. Here is an example: SchoolA is large, has lots of majors, a very little on campus housing. SchoolB is small, medium number of majors, and lots of on campus housing. SchoolA: Large size score=10 Majors=8 Housing=3 SchoolB: Large size score=2 Majors=5 Housing=9 Student1 answers the questions and says they want a large school with lots of majors and lots of on campus housing. The php code would need to create a subscore for each field for each school and then total the score for each school. In this example the scoring would go like this: SchoolA gets 10 points for size, 8 points for majors, 3 points for housing (21 points total). SchoolB gets 2 points for size, 5 points for majors, 9 points for housing (16 points). So, SchoolA would be the best match here. If there were thousands of schools and 10 questions this would obviously get a lot more complicated, but it will still be the same idea. The scoring would be different if a student answered the questions differently. So if Student2 said they wanted a small school, lots of majors and lots of on campus housing the scoring would go like this: SchoolA would get 1 point for size (if the student said they wanted small then the scoring would be reversed for the size variable), 8 points for major, 3 points for housing for a total of 12 points. SchoolB would get 8 points for size, 5 points for majors, 9 points for housing (22 points total). So, schoolB would be the best match for student2. Here is my question. Is this going to be ridiculously complicated to code? If there were 1000 schools with 10 questions, would this require millions of individual temporary variables to calculate and store individual scores for each school? I think the logic works for this, but I’m just trying to make sure it can be coded in a practical and reasonable way. Thanks! Mark Quote Link to comment https://forums.phpfreaks.com/topic/235696-is-this-possible-in-php/#findComment-1211657 Share on other sites More sharing options...
xyph Posted May 6, 2011 Share Posted May 6, 2011 This should be very simple. It will only be as complicated as the amount of data you want to compare. Making this efficient would probably involve a lot of caching. Generally, you're going to select all values from all schools, and compare them one at a time to the desired settings. I would give a points for the difference between the desired and the listed. The more points a school has, the less desirable it will be for that student. In other words, if a student wanted a = 1, b = 5, c = 3, d = 9 and a school was a = 5, b = 3, c = 4, d = 2, the score would be (|a-a|)4+(|b-b|)2+1+7 = 14 another school a = 2, b = 4, c = 5, d = 4, score would be 1+1+2+5 = 9 The second school would have a lower total difference between the desired results, thus be more desirable. Again, the only tricky thing here would be making the code efficient. Quote Link to comment https://forums.phpfreaks.com/topic/235696-is-this-possible-in-php/#findComment-1211662 Share on other sites More sharing options...
rbrown Posted May 6, 2011 Share Posted May 6, 2011 Another idea is just looking through the database based on the students ranking for each question instead of the point system. If no exact match, then deindex each student answer by -1 until you get a match. Or you could allow a +-1 "find" range for each question and if no match then expand the range by 1. So the second time around would be +-2. And so on. That way you are only testing 10 variables at a time in instead of calculating a ton of variables for each school. And with your point system the logic to match the 10 different variables would be a pain or if you calculated like below if you may not get the correct results... Student a=9 b=1 c=0 d=9 = 19 Schools a=5 b=6 c=5 d=3 = 19 a=1 b=9 c=9 d=0 = 19 Not even close to what they would want... Quote Link to comment https://forums.phpfreaks.com/topic/235696-is-this-possible-in-php/#findComment-1211674 Share on other sites More sharing options...
xyph Posted May 6, 2011 Share Posted May 6, 2011 It a good idea, but not efficient. You're comparing a,b,c,d to the entire database 10 times, rather than comparing once and sorting by the end result. You're missing my point as well. I'm not adding a+b+c+d for each school, im doing abs(student_a - school_a) + abs(student_b - school_b) + abs(student_c - school_c) + abs(student_d - school_d) = score. The lower the score, the closer the school is OVERALL to what the student wants. Quote Link to comment https://forums.phpfreaks.com/topic/235696-is-this-possible-in-php/#findComment-1211689 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.