I'm trying to get this statement to select all of the column called "Roles" where Status = 0. With the code I have it is only picking the first one with status = 0. I feel stupid asking but how could I select all roles where status = 0? Current Code:
$sql_query="SELECT Role FROM roles Where Status=0";
$result = mysqli_query($dbconfig,$sql_query);
$input = mysqli_fetch_array($result);
$role = array_rand($input, 2);
echo "<br>";
echo "You are are a ".$input[$role[1]] . "\n";
Note: $dbconfig is coming from a required file in a different location.
Why are you using array_rand()
array_rand — Pick one or more random entries out of an array
http://php.net/manual/en/function.array-rand.php
Try something like this:
$sql_query="SELECT Role FROM roles Where Status=0";
$result = mysqli_query($dbconfig,$sql_query);
while($row = mysqli_fetch_array($result))
{
$role = $row[0];
echo "<br>";
echo "You are are a ".$role . "\n";
}
Based on your comment, maybe this:
$sql_query="SELECT Role FROM roles Where Status=0";
$result = mysqli_query($dbconfig,$sql_query);
$myRoleArray;
while($row = mysqli_fetch_array($result))
{
$role = $row[0];
$myRoleArray[] = $role;
}
//You can pick random from $myRoleArray now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.