1
1
1programmer2018-02-26 15:06:36
PHP
1programmer, 2018-02-26 15:06:36

How to display random questions on page refresh?

Hi all.
There is a list

<div class="b-question">
                  <p>Первый вопрос</p>
                  <ul>
                    <li><label><input name="q1" type="radio" value="a">Первый ответ</label></li>
                    <li><label><input name="q1" type="radio" value="b">Второй ответ</label></li>
                    <li><label><input name="q1" type="radio" value="c">Третий ответ</label></li>
                    <li><label><input name="q1" type="radio" value="d">Четвертый ответ</label></li>
                  </ul>
              </div>

It is necessary that when the page is reloaded, the answers change places, so that each user has his own order. How to implement it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
Lander, 2018-02-26
@1programmer

If you want to mix at the front, then here is the solution to your problem.
upd. And also they asked .
upd 2. In general, learn to google . :)

S
Stalker_RED, 2018-02-26
@Stalker_RED

$перемешанные = shuffle($массив_с_вопросами);
php.net/manual/en/function.shuffle.php

P
po5epT, 2018-02-26
@po5epT

So answers or questions are needed randomly? although the essence does not change.
There is an array of answers/questions retrieved from the database.

$answers  = [1,2,3,4,5];
$shuffledAnswers = shuffle($answers);

echo $shuffledAnswers[0];

That is, the array of questions / answers is mixed and the first one is displayed to the user, it will always be different.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question