选定的 id 将选择行并随机化。但是,它可以随机化相同的元素。例如:“我喜欢弹钢琴。” 我期望的输出被随机分配到例如。'弹奏喜欢我的钢琴'但有时我收到的结果是'我喜欢钢琴钢琴'这句话来自数据库(phpmyadmin)。如何使数据全部出现但不重复?
$strSQL = "SELECT * FROM sentences WHERE id
ORDER BY RAND() LIMIT 1;";
$x = rand(1,4);
echo "$x";
$y = rand(1,4);
echo "$y";
$z = rand(1,4);
echo "$z";
$c = rand(1,4);
echo "$c";
$rs = mysql_query($strSQL);
// Loop the recordset $rs
while($row = mysql_fetch_array($rs)) {
// Write the data of the person
echo "<dt>Sentence:</dt><dd>" . $row["$x"] . " " . $row["$y"] . " " . $row["$z"] . " " . $row["$c"] ."</dd>";
}