[SOLVED] Comparing MySQL data with PHP

09-22-06, 02:25 PM
|
|
Newbie Coder
|
|
Join Date: Jun 2006
Location: Boston
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
[SOLVED] Comparing MySQL data with PHP
This may be complicated, or entirely impossible, I don't know, but it can't hurt to ask.
I've got information in my MySQL database (submissions from a form), that I need to compare to one individual row. Is this possible?
Further elaboration:
We've run a contest where users have had to vote in 16 different categories (best movie, worst movie, etc), those entries are dumped into my MySQL database, one row per entry.
Each category on the form has it's own entry.
At the end of the contest, I will then add a row to the database for what won each category.
Can I then write a script (and if so, how?) to compare all the data to the "Winner" row, and tell me via output how many of each row matched the winners?
Example of the database is: IP, Name, EMail Address, Worst Movie, Best Ensamble Cast, Best Chick Flick, etc..
So, I would need the output to include the e-mail address, and a total number of how many of their entries matched what I put into the "Winners" column, for every single row in the database (in this instance, just shy of 1500)
Possible, and if so, how? Thanks in advance, for any suggestions, you guys are always extremely helpful (and, if this doesn't make sense to anyone, ask questions, I tend to overthink and overexplain things, to complicate)
|

09-22-06, 10:20 PM
|
|
Wannabe Coder
|
|
Join Date: Jul 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Do something like this (example for the winning worst movie)
|

09-23-06, 08:58 AM
|
|
Newbie Coder
|
|
Join Date: Jun 2006
Location: Boston
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for the help, it's a good start.
It doesn't quite do what I'm looking for though. The code you gave me just gives me the number of times the specific $worst_movie was voted for, and displays the e-mail addresses and names of people who voted for it.
What I need to do, is get that list to compare it to my winner categories.
IE; I'll need to print via output something like this:
This way I'll have a table set with columns of people's names, e-mail addresses, their votes, and how many of those votes (the very last column) actually matched what I've entered as the "Winners"
I've already got a few pages written that display just the votes (I also exported it to Excel, to count votes), but need to know exactly how many votes each person got that matched what I enter as a winner.
Any other ideas, or suggestions?
|

09-23-06, 10:19 AM
|
 |
Community VIP
|
|
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Firstly, storing a row with the answers into the database won't help. You cannot compare the other rows with that row any easier than just forming a query with the answers in it.
If the 16 categories and the corresponding answers were stored as 16 separate rows using each person's name, I can think of a way to form a query using a GROUP BY and a COUNT that would give results ordered with the person having the most correct answers first... down to the person with the least correct answers. It would be similar to this - http://www.programmingtalk.com/showthread.php?t=29827
However, it seems from the definition you have written that there is one row per person with all their answers in the row. It may be possible to form a complicated query involving sub-queries and counts... that will do this, but I can think of a straight forward way to do this in PHP. Code to follow in a separate post...
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
|

09-23-06, 10:59 AM
|
 |
Community VIP
|
|
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The following should work or be close (tested except for actual database results) -
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
|

09-23-06, 11:32 AM
|
|
Newbie Coder
|
|
Join Date: Jun 2006
Location: Boston
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You're my hero.
Send me a bill 
|

04-06-08, 08:31 PM
|
|
Newbie Coder
|
|
Join Date: Jun 2006
Location: Boston
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm revisiting this, all this time later.
The code, as above, works great, thanks for that.
What I'm trying to do now, is display a message with each part that matches. So if they get a match, they get a "Correct", and if it doesn't match, they get a "Sorry, wrong"
The code, however, is giving me trouble. What I've tried is this:
What I'm assuming the code would do, but isn't is pull what the person's entry was under each category. ie; $actionmovie="$BestActionMovie", the $BestActionMovie is the variable from the database, where the person's data is stored.
So, if I define what they voted for as $actionmovie, and say if $actionmovie = whatever the winner is, say Correct.
The important part needs to be that $BestActionMovie needs to reflect whatever is stored in the database for the e-mail address specified.
It's not working. I'm thinking that how I've written the code to define what the person's vote was for, isn't working right.
Any suggestions? (Sorry if this sounds confusing, I've been staring at the screen for far too long, and may not be making sense)
Thanks for any advice/help.
|

04-06-08, 09:44 PM
|
|
Newbie Coder
|
|
Join Date: Jun 2006
Location: Boston
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Scratch that, I figured it out.
Is what works for me.
Unless someone's got a better suggestion, I consider this all set.
|

04-07-08, 03:48 PM
|
|
Newbie Coder
|
|
Join Date: Jun 2006
Location: Boston
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by mab
The following should work or be close (tested except for actual database results) -
|
Trying to expand on this a bit, to make the output only display one email address, which works.
However, it displays it as: Is there a way I can do the following, based on your example?:
1) Remove the word "Array"?
2) Remove the ([ and] =>
I basically just want to show the e-mail address, and how many matches there were from the array. I've messed around with it for a while, but can't figure out how to modify the output of the array.
|

04-10-08, 10:39 AM
|
|
Newbie Coder
|
|
Join Date: Jun 2006
Location: Boston
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Figured it out thanks to one of the engineers at work.
Resolved.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|