php - Using foreach loop inside a while loop and echo the values -


i have website people can upload videos , if user uploads video makes new folder called videos in folder e.g. user/someone/videos/videoname , in videos folder there videos user uploaded. inserts video database. works fine, when try echo these videos in html video tag have problems. since user can upload more videos created array called $url. select videos belong user ($sql = "select * videos user=?";). push every video item $url array , echo videos foreach loop. , here wrong. there're duplicates, 1 video echoed more times , there're missing urls.

code:

$echo_videos = ""; $items = ""; $url = array(); $sql = "select * videos 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 $key) {         $echo_videos .= '<video width="400" controls><source src="'.$key.'"></video>';     } } 

ps: maybe $items variable should array won't able push array another.

why not echo filename

while($row = $result->fetch_assoc()){    echo '<video width="400" controls><source src="user/'.$u.'/videos/'. $row["video_file"].'">          </video>'; } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -