I have two table of same data. First table is written by the admin and the second data is written by the user. Now I want to compare these two and see if they match, if not then the correct data is displayed.

So far I am retrieving the user's current details and now I would like to compare this with the admin, but stuck. Can someone help me.

the two table format :

Admin table
Que_ID
Que_Answe1
Que_Answer2
Que_Answer3
Que_Answer4

User table
Que_ID
Ans_Answer1
Ans_Answer2
Ans_Answer3
Ans_Answer4


The code to retrieve user table is

<?php

$intNumber = 1;
$sql=correctanswer($_SESSION['username1'], $_SESSION['smodule']);

     while($info = mysql_fetch_array( $sql )) { 
	echo " $intNumber,  {$info['Que_Question']} <br />\n";
	
	if($info['Ans_Answer1'] == '1') {
	echo "<input type=\"checkbox\" name=\"choice1[]\" value='1'\" checked> ";
	echo "{$info['Que_Choice1']} <br />\n";
	}
		else {	
				echo "<input type=\"checkbox\" name=\"choice1[]\" value=\" {$info['Que_Choice1']}\" /> ";
				echo "{$info['Que_Choice1']} <br />\n";
			}
			
	if($info['Ans_Answer2'] == '1') {
	echo "<input type=\"checkbox\" name=\"choice2[]\" value='1'\" checked> ";
	echo "{$info['Que_Choice2']} <br />\n";
	}
		else {	
				echo "<input type=\"checkbox\" name=\"choice2[]\" value=\" {$info['Que_Choice2']}\" /> ";
				echo "{$info['Que_Choice2']} <br />\n";
			}
			
	if($info['Ans_Answer3'] == '1') {
	echo "<input type=\"checkbox\" name=\"choice3[]\" value='1'\" checked> ";
	echo "{$info['Que_Choice3']} <br />\n";
	}
		else {	
				echo "<input type=\"checkbox\" name=\"choice3[]\" value=\" {$info['Que_Choice3']}\" /> ";
				echo "{$info['Que_Choice3']} <br />\n";
			}
	if($info['Ans_Answer4'] == '1') {
	echo "<input type=\"checkbox\" name=\"choice4[]\" value='1'\" checked> ";
	echo "{$info['Que_Choice4']} <br />\n";
	}
		else {	
				echo "<input type=\"checkbox\" name=\"choice4[]\" value=\" {$info['Que_Choice4']}\" /> ";
				echo "{$info['Que_Choice4']} <br />\n";
			}
	$intNumber++; 
	} 
	?>
Member Avatar
diafol

First of all your title states two databases. You go on to describe two tables. Are they from the same DB or from two different databases?

oops.... I apologies they are two tables...

Member Avatar
diafol

The user table is just for one user then? No way to get more than one user into that - no user_id column.

nope, you can have many users. User_ID is defined in another table. I only splitted the table into admin and user to explain what I wanted the system to do. Bur originally admin table is the question. and the user table is answer.

Member Avatar
diafol

Well, would you like to give us the proper structure of the users table?

OK, in the meantime, something like this:

SELECT results.id, IF(results.q1 = users.q1 AND results.q2 = users.q2 AND results.q3 = users.q3 AND results.q4 = users.q4, "Correct","Wrong") AS result FROM results LEFT JOIN users ON results.id = users.id WHERE users.user_id = 1

User table structure is: Use_ID, UserName, UserPassword,Role_ID

I am lost with your code :S

Member Avatar
diafol

I am totally lost with you.
How are your answers linked to the user?
You have something like:

USERS TABLE
user_id | username | userpw | role_id
ADMIN
que_id | ans_1 | ans_2 | ans_3 | ans_4
USER TABLE
que_id | ans_1 | ans_2 | ans_3 | ans_4

How do the users join to the useranswers?

My query is based on the join being made on the question number and comparing admin answers with user answers. It looks as though you're storing '1' and '0' in ans1,2,3,4 if you're using multiple choice. If not, I don't know what you're doing.

Yep I am storing the answers as 1 and 0's.

And they are joined by using User_ID.
Answer table has User_ID. but this user_ID is to determine which user took the exam.

when the admin created the questions he/she set an test. Test is another table. This is where the admin User_ID is stored.

Have I confused you???

Member Avatar
diafol

Totally. Sorry.

I really can't see why you didn't store values 0-4 in a single answer column. You've made a rod for your back with this.

Anybody else give a hand?

Its ok.

The reason for that is because they can choose more then one answer.

thanks for trying though :)