Hi.
I have a table like the one below in mysql:
id word sentance answer explanation
1 happy I am sorry for your unhappines unhappiness
2 consume I am a consumer consumer
3
First I am trying to do is create the variable ‘$answer’ which captures in the random row generate , the content in the column "answer" of that row for exampls ‘unhappiness’
To generate the random I am using the code below:
<?php
$con = mysql_connect ("localhost", "root", "root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("clients", $con);
$range_result = mysql_query( " SELECT MAX(`wd_id`) AS max_id , MIN(`wd_id`) AS min_id FROM `words` ");
$range_row = mysql_fetch_object( $range_result );
$random = mt_rand( $range_row->min_id , $range_row->max_id );
$result = mysql_query( " SELECT * FROM `words` WHERE `wd_id` >= $random LIMIT 0,1 ");
mysql_close($con);
?>
To echo the random the random answer I am using the following code.
<?php
while($row = mysql_fetch_array($result))
{
echo "<table border ='0' width='600px'>";
echo "<tr>";
echo "<td width='100px'> <font color='black'> Clue word: </font></td>";
echo "<td width='100px'>" . $row['wd'] . "</td>";
echo "<td width='150px'> <font color='black'>Context sentence: </font></td>";
echo "<td width='200px'>" . $row['st'] . "</td>";
echo "<td>" . $row ['wd_id'] . "</td>";
echo "<td>" . $row ['answer'] . "</td>";
echo "</tr>";
}
echo"</table>";
?>
I also have a text input box and a submit button.
I want to compare the word typed in the input box with the random word.
If they are the same I want to echo the word in green
If not I want to echo the typed word in red
The code I have is as below:
To compare and green or red:
<?php
$input = $_POST['1'];
if (isset ($_POST['SUBMIT'])){
if ($input == $answer)
echo "<font color='green'>" . $answer . "</font> ";
else echo "<font color='red'>" . $input . "</font>";
echo $explanation;
echo $related;
echo $pron;
}
?>
the problem I have is that
when I try comparing the input from the form to the variable $answer, it doesn't compare.
Basically because I are not able to define to variable $anwer with the information I want it to have.
I need the the code that defines the variable $answer (which would be content in the columna "answer" of the random row generated by the variable $result).
Any help would be very welcome
Many thanks


