php - Select Random and unique rows from database on button click -


i trying develop quizz app in php , mysql. have case have 1 random row database on button click. , question appeared once should not appear next time.

what did was, selected random row database stored id on session variable array. , next time while fetching data of random row checked if questions id lies on array or not. if question id on array reload page new question else display question.

the code have used follows code select random , unique row

code display value , save value on array

enter image description here enter image description here

sorry!, couldn't put code in here due format problem.

using way, when every question on database shown user, page enter infinite redirection loop. might use query this:

 select * tbl_question       question_id not in ([previously shown ids]) , is_active='yes'       order rand() limit 1 

this way, if don't result, you'd assume questions have been shown user, , won't need page refresh switch question when question exists in session variable.

in code, modify:

 $where = "is_active='yes'" 

to

 $where = "is_active='yes' , id not in (" . implode(",", $_session["ques"]) . ")"; 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -