Hi all I am a php MySQL noob but I needed to make a quiz for one of my web sites.
Now its all up and ruining and I still cant believe I managed it
But now its working I want to iron out a few problems
I have six and then 3 questions on each page now I run the same piece of code 6 times for the six questions then anther piece of code 3 times for the other 3.
I’ve read about functions and have played around with them no problem but I just can’t seem to put my MySQL query into a function .
If I could do this it would mean less code but more inportant I think I could get the id and use an else statement to stop repeating questions.
This i s the code i run six times per page ive changed the output which i have echoing in to a javascript button just to make it easier to read
[php]
#select a query
$sql = “SELECT * from quiz_korean WHERE cat = ‘one_kup_korean’ ORDER BY RAND() LIMIT 1”;
#excute query
$dbname = mysql_query ( $sql );
#write data
while ( $row = mysql_fetch_array ( $dbname ) )
{
$Q = ( $row["question"] );
$A = ( $row["answer"] );
echo $Q;
echo $A;
}
[/php]
Now if i could put into a function
i guess i could grap the id from my table and use some an if else statment to stop the same question being outputed.
I assumed i could put above code into a function less the 2 echos
then just use
[php]
my_func ()
{ echo $Q ;
echo $A;
}[/php]
Thanks fro any help .
view quiz Here