How to write if statement in MySQL

Hi everyone….
I have a table in my database comprising of ‘yesnoquestion_id’, ‘student_id’, ‘student_answer’, ‘answer’.
I need to get some information out into my webpage interface using MySQL. I need to output the number of student whose answers answers are correct to the right answer into a table that will show on the interface….. the write answer is ‘answer’ while the students’ answer is ‘student_answer’.

Here is what i have done so far:

PHP Code:
<?php

global $connection;
$query = "SELECT yesnoquestion_id AS Question_No, if (answer = 1, ‘TRUE’, ‘FALSE’) AS Answer, Count(student_id) AS num1
FROM yesnoanswers
WHERE student_answer = answer
GROUP BY yesnoquestion_id
ORDER BY yesnoquestion_id ASC "
;
$collate_set = mysql_query($query, $connection);

//Drawing table and inserting data into it
echo "<table border=’5′>
<tr>
<th>Question Number</th>
<th>Question Answer </th>
<th>No. of Student correct</th>
</tr>"
;
while (
$row = mysql_fetch_array($collate_set))
{
echo
"<tr>";
echo
"<td>" . $row ['Question_No'] . "</td> ";
echo
"<td>" . $row ['Answer'] . "</td> ";
echo
"<td>" . $row ['num1'] . "</td> ";
echo
"</tr>";
}
echo
"</table>";
?>

This is outputting just the ‘YESNOQUESTION_ID’, ‘NUMBER OF STUDENTS’, ‘STUDENT_ANSWER = ANSWER’.

How can i get it to also output the ‘STUDENT_ANSWER != ANSWER’ i.e where ‘student_answer’ IS NOT ‘answer’ on the same table ?

Thank you

View full post on Tycoon Talk

, ,

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Get Adobe Flash playerPlugin by wpburn.com wordpress themes


RSS Site FeedRSS Site Feed

© 1992-2011 DC2NET™, Inc. All Rights Reserved