Jump to content

puyunk

Members
  • Posts

    11
  • Joined

  • Last visited

puyunk's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I am more confused now.. Can you show me the code in how to do that? How to put the ID of the question that are already used in an array, and connect them using session.. Did not have any vision in how to do that..
  2. Sorry to keep bothering, but this code $ids = implode(',',$_SESSION['used']); keep giving me errors.. and since I am really new in PHP code, I am really unfamiliar with your second line also.. $not_in = empty($ids) ? '' : " AND SoalID NOT IN($ids)"; the error that I get is like this.. undefined index in line 17 <-- which is the first line of the updated code.. I changed my query into yours, and add the first and second line of the code right on top of it.. Need more information about this.. Thanks before hand..
  3. Do you have any suggestion in how to make it just like what i need? Would it be work if i do the shuffling inside the sql query rather than in the array? It raised another problem, what kind of query then..
  4. Oh wow.. I think i found the reason why the question is not loaded perfectly if i used shuffle().. The quiz are loaded inside a flash file, to load the question, I connect the array result to it.. The code inside the flash file (actionScript) is as follows: .... var questionID:String = arrContent[0]; var questionL:String = arrContent[1]; var answerS1:String = arrContent[2]; var answerS2:String = arrContent[3]; var answerS3:String = arrContent[4]; var answerS4:String = arrContent[5]; var correctAnswer:String = arrContent[6]; ..... so, if i shuffle() the array, then the string will all be different.. That is why the code is not working as i wanted.. Seeing this, it raise another question.. How to randomize the array without changing the array numbers..
  5. There are two screenshot I attached in this post.. the first one is when I used my old codes.. and second one is when I used your codes...
  6. <?php include "databaseconnection.php"; if ($_GET) { $topic=$_GET["topic"]; $level=$_GET["level"]; $levelStr=""; if ($level==0) { $levelStr="Easy"; } else if ($level==1) { $levelStr="Medium"; } else if ($level==2) { $levelStr="Hard"; } $sqlText="SELECT * FROM soal WHERE Difficulty='". $levelStr ."' AND Topic='". $topic ."'"; $result=mysql_query($sqlText); $ctr=0; $arr=null; while($row = mysql_fetch_array($result)) { $arr[$ctr]=$row["SoalID"]."#".$row["Question"]."#".$row["Answer1"]."#".$row["Answer2"]."#". $row["Answer3"]."#".$row["Answer4"]."#".$row["CorrectAnswer"]."#".$row["Picture"]; $ctr++; } // if ($ctr>0) // { // $totalRand=rand(10,50); // for ($i=0;$i<$totalRand;$i++) // { // $idx1=rand(0,$ctr-1); // $idx2=rand(0,$ctr-1); // // $res=$arr[$idx1]; // $arr[$idx1]=$arr[$idx2]; // $arr[$idx2]=$res; // } // $idx=rand(0,$ctr-1); // echo $arr[$idx]; // } if ($ctr>0){ shuffle($arr); foreach($arr as $question){ echo $question; } } } ?> Here's the code to get the question from the database.. I commented my old codes, and changed them to yours..
  7. Then what should I do? I reached a stuck point.. What kind of code should I put here so you can help me solved this?
  8. Thanks for the quick reply.. Yes, I did try it more than once.. I changed my current code to the code you posted before, with nothing else change, i mean the codes before them..
  9. Hey, thanks for the replies. I did some research about shuffle(), it seems if i use shuffle() to randomize the questions, it seems only reversing the array data, for example array(1,2,3) becomes (3,2,1) or am I taking the wrong conclusion? And about the code you posted, why is it not working for me? I mean, the questions are still repeatable and its not loaded clearly, i mean the answer and question data are all mixed up. Can you give me another suggestion? Or should i post the screenshot? Thanks before..
  10. Its not working. The loaded data still repeatable. I'm thinking I should change this code rather than the sql, but I'm kinda confused what should I change here. if ($ctr>0) { $totalRand=rand(10,50); for ($i=0;$i<$totalRand;$i++) { $idx1=rand(0,$ctr-1); $idx2=rand(0,$ctr-1); $res=$arr[$idx1]; $arr[$idx1]=$arr[$idx2]; $arr[$idx2]=$res; } $idx=rand(0,$ctr-1); echo $arr[$idx]; }
  11. Hi all, So basically, I tried to generate random questions from database using mySQL and PHP. I success in generating those questions, BUT the questions can sometimes appear again. I have this PHP code of mine.. ....... $sqlText="SELECT * FROM soal WHERE Difficulty='". $levelStr ."' AND Topic='". $topic ."'"; $result=mysql_query($sqlText); $ctr=0; $arr=null; while($row = mysql_fetch_array($result)) { $arr[$ctr]=$row["SoalID"]."#".$row["Question"]."#".$row["Answer1"]."#".$row["Answer2"]."#".$row["Answer3"]."#".$row["Answer4"]."#".$row["CorrectAnswer"]."#".$row["Picture"]; $ctr++; } if ($ctr>0) { $totalRand=rand(10,50); for ($i=0;$i<$totalRand;$i++) { $idx1=rand(0,$ctr-1); $idx2=rand(0,$ctr-1); $res=$arr[$idx1]; $arr[$idx1]=$arr[$idx2]; $arr[$idx2]=$res; } $idx=rand(0,$ctr-1); echo $arr[$idx]; } } Any idea how to fix this problem? Appreciate any help.. Thanks before
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.