简体   繁体   English

如何从 RAND() 获取两条不同的记录?

[英]How to get two different records from RAND()?

I am making an exercise related app.我正在制作一个与锻炼相关的应用程序。 My plans are for day A and day B. I have a database with a list of exercises in it.我的计划是 A 天和 B 天。我有一个数据库,里面有练习列表。 When I try to search for a given exercise, it is drawn for day A. But when I try to draw it for day B, it happens that the two are the same data.当我尝试搜索给定的练习时,它是为 A 天绘制的。但是当我尝试为 B 天绘制它时,恰好这两个是相同的数据。 I tried to compare these two data, but I still fail.我试图比较这两个数据,但仍然失败。

$e_legs_B = "SELECT * FROM exercises WHERE body_part = 'Quad' AND difficulty = 'Easy' ORDER BY RAND() LIMIT 1";
$e_legs_B_run = mysqli_query($conn, $e_legs_B);

Then in body my code looks like this.然后在正文中,我的代码如下所示。

<?php
$rows = $e_legs_B_run->fetch_assoc();
$name = $rows['name'];
echo "<option value = '$name'>$name</option>";
?>

Select data for day a and b in one query and split the result. Select 在一次查询中获取 a 天和 b 天的数据并拆分结果。

Or store the id's from day a in an array and exclude them in the second query for day b.或者将 a 天的 id 存储在一个数组中,并在 b 天的第二个查询中排除它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM