I have a website where people can upload their videos and if a user uploads a video it makes a new folder called videos in their folder e.g. user/Someone/videos/videoname and in the videos folder there are all the videos that the user uploaded. Then it inserts the video into the database. That works fine, but when I try to echo these videos in an HTML video tag I have problems. Since a user can upload more videos I created an array called $url. Then I select those videos that belong to that user ($sql = "SELECT * FROM videos WHERE user=?";). Then I push every video item to that $url array and I echo the videos with a foreach loop. And here is something wrong. There're duplicates, so one video will be echoed more times and there're missing urls.
Code:
$echo_videos = "";
$items = "";
$url = array();
$sql = "SELECT * FROM videos WHERE user=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s",$u);
$stmt->execute();
$result = $stmt->get_result();
while($row = $result->fetch_assoc()){
$name = $row["video_file"];
$items .= "user/$u/videos/$name";
array_push($url, $items);
foreach ($url as $key) {
$echo_videos .= '<video width="400" controls><source src="'.$key.'"></video>';
}
}
PS: Maybe the $items variable also should be an array but then I won't be able to push an array to another.