是否有任何查询,允许用户从数据库一次只选择随机行 [英] is there any query that allows user to select random rows from database one time only

查看:100
本文介绍了是否有任何查询,允许用户从数据库一次只选择随机行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查询从数据库只选择随机行一次。我的意思是一次后如果用户按刷新按钮行应该保持不变。目前我正在做

I want query to select random rows from database only for one time.I mean to say after one time if user press refresh button rows should remains the same. currently i am doing

SELECT * from table-name order by rand() limit 5;

此查询每当用户按下刷新按钮或刷新页面时选择随机行。

this query selects random rows every time when user press refresh button or refresh page.

在PHP文件中我正在做

in php file i am doing

$query="SELECT * from question_bank order by rand() limit 10";
$result= mysqli_query($connection,$query);
confirm_query($result);

?>

<form action="result.php" name="form1" method="post" id="quiz">
<?php
while ($read_all_data = mysqli_fetch_assoc($result))
{ 
    $_SESSION['id']=1;

$id=$read_all_data['question_id'];
$a=$read_all_data['a'];
$b=$read_all_data['b'];
$c=$read_all_data['c'];
$d=$read_all_data['d'];
 echo $read_all_data['question']."</br>";
 echo "A:<input type ='radio' value ='a'  name='$id' >".$read_all_data['a']."</br>";
 echo "B:<input type ='radio' value ='b'  name='$id' >".$read_all_data['b']."</br>";
 echo "C:<input type ='radio' value ='c'  name='$id' >".$read_all_data['c']."</br>";
 echo "D:<input type ='radio' value ='d'  name='$id' >".$read_all_data['d']."</br>";

}


推荐答案

查询在您的Web应用程序的会话中的结果。在页面加载期间,检查结果是否在会话中,如果结果在会话中显示。如果没有,则查询数据库。

Store the results of the query in the session of your web application. During page load check if the results are in the session and display them from there if they are. If not, then query the database.

这篇关于是否有任何查询,允许用户从数据库一次只选择随机行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆