CodeIgniter如何在不重复ID的情况下使用rand()

时间:2018-12-30 20:37:05

标签: javascript php html mysql codeigniter

所以我正在使用MVC在CodeIgniter中进行测验,到目前为止,我有这个查询,可以从Perguntas表中获得问题,而从Resposta表中得到答案。

因此,我要进行10个问题的测验,其中每个问题仅在视图中单独显示,问题是每次单击下一步时,我都会得到一个已回答的重复问题。相同的测验,所以基本上我会遇到重复的问题。

有什么主意如何解决这个问题而不重复相同的问题吗?

  

Blockquote   这是我的模型:

$query = $this->db->query("SELECT PERGUNTAS.ID_PERGUNTA, PERGUNTAS.NOME_PERGUNTA, RESPOSTA.RESPOSTACERTA, RESPOSTA.RESPOSTAERRADA1, RESPOSTA.RESPOSTAERRADA2, RESPOSTA.RESPOSTAERRADA3
    FROM PERGUNTAS 
    INNER JOIN RESPOSTA
    WHERE PERGUNTAS.ID_PERGUNTA = RESPOSTA.ID_RESPOSTA
    AND PERGUNTAS.TEMA = 'Futebol'

    ORDER BY Rand() LIMIT 1");
     return $query->result();
  

Blockquote   这是我的控制器

public function IniciarJogoFutsal()
 {
if($this->session->userdata['logged_in']['id_util'])

    {
if($this->session->userdata['logged_in']['isadmin'] !=0)
 {
$this->load->model('Jogo_model');
$data['list'] = $this->Jogo_model->BuscarPerguntasRespostasFutsal();
$this->load->view('header_admin');
$this->load->view('jogo_futsal', $data);
 }
if($this->session->userdata['logged_in']['isadmin'] !=1)
     {  
        $this->load->model('Jogo_model');
$data['list'] = $this->Jogo_model->BuscarPerguntasRespostasFutsal();
$this->load->view('header_user');
$this->load->view('jogo_futsal', $data);
     }
    }
else
{
    redirect('Login/index');
}
}
  

Blockquote   这是我的观点jogo_futsal的一部分,当我单击下一个问题时,它会刷新页面

<?php foreach($list as $quiz): ?>
<label style="color: #ffffff; word-wrap: break-word; transform: skew(20deg);font-weight: 900; text-shadow: 1px 0 #ffffff;"><?php echo  $quiz->NOME_PERGUNTA;?>      </label>    

<?php endforeach ?> 

0 个答案:

没有答案