我需要6个人的3个问题。但每次随机显示快4题。
/*for random question*/
public function qustionShow($question){
$query = $this->conn->query("select * from question where cat_id='$question'");
$c = mysqli_num_rows($query);
$rand = rand(3, $c)-3;
$show = $this->conn->query("select * from question where cat_id ='$question' and id >'$rand' LIMIT 3");
while ($row=$show->fetch_array(MYSQLI_ASSOC)){
$this->qus[]=$row;
}
return $this->qus;
}
1条答案
按热度按时间06odsfpq1#
您可以使用order by rand()减少和优化代码。
尝试以下操作: