我知道按 rand() 排序并不是从数据库中提取随机值的最快方法,但我的数据库很小,而且在这一点上;我只是想让它工作!哈哈。这是我的代码:
include('includes/dbc.php');
$top_query = "SELECT * FROM top WHERE 'occasion_id =" . $occasion . "' AND 'temperature_id = " . $temperature . "' AND 'user_id = " . $user_id . "'ORDER BY RAND() LIMIT 1";
$top_result = mysqli_query($dbc, $top_query) or die (' The top SELECT query is broken.');
mysqli_close ($dbc);
while($row= mysqli_fetch_array($top_result)) {
echo 'This top has an id of:' . $row['top_id'] . '<br> ';
echo 'Does this top require pants?' . $row['needs_pants'] . '<br>';
echo 'What\'s the colour id of this top?' . $row['colour_id'] . '<br>';
echo $row['value'];
}
出于某种原因,这不起作用,当我尝试运行我的数组时,我只会显示空白。在我按“rand() limit 1”位输入顺序之前它起作用了,但显然我得到了每个值而不是一个随机值。
谁能看到我哪里出错了?非常感谢!