prepare("select id from 3312canswer where questionid = ? and answer = ?"); $num->execute(array($qid,$answer)); $i = 0; while ($row = $num->fetch()){ $i++; } if ($i == 0) echo 'you got it wrong!
'; $getsql= $dbh->prepare("select description from 3312wanswers where questionid = ? and answer = ?"); //get wrong answer description $getsql->execute(array($qid,$answer)); $getrow = $getsql ->fetch(); echo $getrow[0].'
'; //we insert into users table $inssql = $dbh->prepare("insert into 3312useranswers (answer,timeanswered,sessid,question) values (?,now(),?,?)"); $inssql->execute(array($answer,$sessid,$qid)); //print_r($inssql->errorInfo());//this is a pdo only error function... //then we will ask the next question $sql = $dbh->prepare("select questionid, question from 3312questions where questionid not in (select question from 3312useranswers where sessid = ?) order by rand() limit 1"); $sql->bindValue(1,$sessid); $sql->execute(); $i=0; //counter for total values to check and see if we're done? while ($qidrow = $sql->fetch()){ $newqid = $qidrow[0]; $newquestion = $qidrow[1]; $i++; } if ($i == 0) { echo 'Quiz Over!
';// //what is my score? $num = 3; $getscore = $dbh->prepare("select 3312canswer.id from 3312canswer, 3312useranswers where 3312canswer.answer = 3312useranswers.answer"); //get number of answers right $getscore->execute(); $y =0; while ( $total = $getscore->fetch()){ $y++; } echo 'Your score is '.$y.' out of '.$num.'
'; } else { echo $newquestion.'
'; $csql = $dbh->prepare("select answer from 3312canswer where questionid = ?"); $csql ->bindValue(1,$newqid); $csql->execute(); $crow = $csql->fetch(); $answer = $crow['answer']; $possibleanswers = array(); $possibleanswers[] .= $answer; //same $wsql = $dbh->prepare("select answer from 3312wanswers where questionid = ?"); $wsql ->bindValue(1,$newqid); $wsql->execute(); while ($wrow = $wsql->fetch()){ $possibleanswers[] .= $wrow['answer']; } shuffle($possibleanswers); foreach ($possibleanswers as $ans){ $arianna .= ''.$ans.'
'; } echo $arianna; } ?>