how to randomize retrieval of question from database?

后端 未结 5 1642
南旧
南旧 2021-01-20 15:06

.i have the following code:



        
5条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-20 15:19

    Try this :

    here is code to get results :

        $total = @mysql_num_rows(mysql_query("SELECT * FROM questions WHERE QuizID=1"));
        $per_page = 5;
        $page = $_GET['page'];
        $query = "SELECT * FROM questions WHERE QuizID=1 , id >= (SELECT FLOOR( MAX(id) * RAND()) FROM `table` ) ORDER BY id LIMIT " . mysql_real_escape_string($per_page) ." OFFSET " . mysql_real_escape_string($page * $per_page) . "";
    

    here is code to "next page" :

        if($total >= ($page * $per_page))
        {
          echo 'Next Page';
         }
    

    maybe you have to change something in my code, because i haven't tried it to see if it works.

提交回复
热议问题