Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

mysql or php compare multiple rows return matches

Codes here !

Moderators: macek, egami, gesf

mysql or php compare multiple rows return matches

Postby tacoma » Sat Jul 13, 2013 8:10 pm

I'm working on a quiz type app. where each user answers 25 questions. Or possibly more. The answers are stored in the database as a 6 digit numerical value. I'm trying to compare user A's answers to user B. I've tried a mysql statement to sort the matches and return the values. Here's what I did.

Code: Select all
SELECT ALL `user_answer_id` FROM `user_answers`  WHERE `user_quiz_id` = (SELECT `id`
FROM `user_quizzes` WHERE `user_id` = (SELECT `id` FROM `imported_users`
WHERE `user_name` = 'Marie'))    WHERE  `user_answer_id` = `user_answer_id` FROM `user_answers`  WHERE `user_quiz_id` = (SELECT `id`
FROM `user_quizzes` WHERE `user_id` = (SELECT `id` FROM `imported_users`
WHERE `user_name` = 'chester'))


This returned a #1242 mysql error stating that "subquery returns more than one row". After doing "some" reading, I find that route isn't going to work, at least the way I attempted it.
Since trying that method I've altered the database so as not to have to make as many sub calls to get at the data.
I'm currently working on finding a simple solution in php to sort and compare the results of two querys.
So far nothing has worked. I could work with a rowcnt of matches.
Anybody got any ideas?
tacoma
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sat Jul 13, 2013 7:21 pm

Re: mysql or php compare multiple rows return matches

Postby johnj » Tue Jul 16, 2013 2:54 am

one way will be to compare the answers in php after you pull the answers for user A and user B.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron