xxtobirichter Posted December 16, 2007 Share Posted December 16, 2007 Hello, I m building a vocabulary trainer for a school project and i m stuck... I ve done the following //select 1 correct answers $answerpick = mysql_query("select id from answer where id='{$image['id']}'"); $answer =mysql_fetch_array($answerpick); //select 3 wrong answers $wronganswer = mysql_query("select id from answer where id<>'{$image['id']}' order by rand() limit 3"); $wanswer= (mysql_fetch_array($wronganswer)) So far so good, I can read all of them out and display the id. I need to randomly put them into a table. My idea was to put them into one array and then randomly give them out... Another thing, in order to evaluate the answer. I thought off an input form where from a drop down the student can choose (A,B,C,D) each linked to the id of one of the answers...anyone an idea or am i completely off track? Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 16, 2007 Share Posted December 16, 2007 you can do that by array randomizing or sql rand eg.. select * from table1 where id in(select id from table2) order by rand() loophere{ add here the incorrect answer } hope that make sense Quote Link to comment Share on other sites More sharing options...
xxtobirichter Posted December 17, 2007 Author Share Posted December 17, 2007 Is the loophere function part of the sql query? How do i add the incorrect answers, as a sql query? Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 17, 2007 Share Posted December 17, 2007 lol no sorry.. loop here means you need to put some loop there to get all your records form your db so that you can match that one by one .. it will help if you post more of that codes and explain it better Quote Link to comment Share on other sites More sharing options...
xxtobirichter Posted December 17, 2007 Author Share Posted December 17, 2007 Ok sure, that s the plant. A vocabulary trainer. From a database we select 1 set of data e.g 1 chinese character, the task is to find the correspondent answer in english. //select 1 character $imagepick = mysql_query("SELECT id, english, py, cc, sound FROM maintb order by rand() limit 1"); $image = mysql_fetch_array($imagepick); //Then we need 4 answers, one of which has to be equal to the 1 character so the student can pick the right one. $answerpick = mysql_query("select id from answer where id='{$image['id']}'"); $answer =mysql_fetch_array($answerpick); //we need to select 3 wrong answers $wronganswerpick = mysql_query("select id from answer where id<>'{$image['id']}' order by rand() limit 3") $wronganswer=mysql_fetch_array($wronganswerpick); Now the part i m struggeling with. The 4 possible answers have to be mixed and given out. For the mixing i had the idea. e.g. $a= $b= $c= $d= $value= array("$a","$b","$c","$d"); $rand_keys=array_rand($value,4); echo "First random element = ".$value[$rand_keys[0]]; echo "<br>Second random element = ".$value[$rand_keys[1]]; echo "<br>third random element = ".$value[$rand_keys[2]]; echo "<br>third random element = ".$value[$rand_keys[3]]; echo ("<br>") That works fine as long as $A, $B, $C, $D are "static variables" (e.g. words, e.g. $A=Good, $B=Bad etc) but it appears that this does NOT work when $a=".$wanswer{'id'}."; I m trying to find a solution for that. If it is possible to assign a variable to ".$wanswer{'id'}." it would also solve the next problem of evaluating the input. Because next step is, Choose A,B,C,D then php if $image('id') = Input then echo ("Correct") else echo ("Wrong"). I am relativly new to PHP and have tried to find a way to store the array values (e.g. ".$wanswer{'id'}.") in variables for the past 2 or 3 days.... Do you have any suggestions? Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 17, 2007 Share Posted December 17, 2007 can you show me the link for this site? Quote Link to comment Share on other sites More sharing options...
xxtobirichter Posted December 17, 2007 Author Share Posted December 17, 2007 This is the first file http://www.voc.tobias-richter.com/files/Print%20Image.php Where i collected the 5 information 1 question 4 answers and have printed them I copied the code outside so it is visible This is the file with a similar start, but instead of printing them direclty i tried to randomly position them http://www.voc.tobias-richter.com/files/array%20random%20position%20test.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.