I'm trying to have my webpage select one random post from a database but it keeps returning an error. The error refers to the 3rd query as a bool rather than an object so there's something wrong with the code. I just don't know what. P.S I'm aware that the rest of the code may be sloppy, just need help with the mt_rand
function.
<?php include('enter-message.php');
$query= $connect->prepare("SELECT MAX( id ) AS 'max_id' FROM userinfo")or die(mysqli_error($connect));;
$query->execute();
$query->bind_result($maximum);
while($query->fetch()){
//print_r($maximum);
}
$query= $connect->prepare("SELECT MIN( id ) AS 'max_id' FROM userinfo")or die(mysqli_error($connect));;
$query->execute();
$query->bind_result($minimum);
while($query->fetch()){
//print_r($minimum);
}
$request=$connect->prepare('SELECT * FROM userinfo ORDER BY mt_rand($minimum,$maximum) LIMIT 1');
if($request->execute()){
while($request==$secret){
echo("<div class='secrets-box'>");
echo($secret['nickname']);
echo($secret['secret']);
echo("</div>");
}