I want to insert the returned values into an array and after to display random string
I have this code by it doesn't return back a random value
Inside the vid1,vid2,vid3 columsn there is Video Name text that pointing to the video in my File Manager folder
$sql = "SELECT vid1, vid2, vid3 FROM table WHERE ID = 2";
$result = $conn->query($sql);
if(!$result) {
echo "Something went wrong, please try again.";
} else {
if($result->num_rows == 0){
echo "Something went wrong, please try again.";
exit();
} else if($result->num_rows >= 1) {
while($row = $result->fetch_assoc()) {
$vid1 = $row['vid1'];
$vid2 = $row['vid2'];
$vid3 = $row['vid3'];
}
}
}
$videos = array(
$vid1,
$vid2,
$vid3
);
$video_to_play = $videos[array_rand($videos)];
And When i hardcode it like this it works. but i am not selecting from the database here.
$videos = array(
'video/202212060125.mp4',
'video/202212060148.mp4',
'video/202212060152.mp4'
);
$video_to_play = $videos[array_rand($videos)];