I have an HTML video player (see code below) with some Javascript (
Here is my HTML code:
<video class="videoPlayer" id="videoplaylist" preload="auto" tabindex="0" controls="">
<source src="video1.mp4">
</video>
<ul id="playlist">
<li>
<a href="video2.mp4"></a>
</li>
<li>
<a href="video3.mp4"></a>
</li>
</ul>
I'm trying to loop through the videos from the database but with the correct HTML structure code above. I'm having issues placing the code correctly inside the while loop. In the future if more videos are were to be added into the database - the only thing that would be added would be more li (list items) under the "playlist" id.
For example:
<li>
<a href="video4.mp4"></a>
</li>
<li>
<a href="video5.mp4"></a>
</li>
<li>
<a href="video6.mp4"></a>
</li>
Here is my SELECT sql with a while loop
$sql = "SELECT title, video_src FROM videos WHERE username = 'admin' ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
// HTML VIDEO PLAYER CODE NEEDS TO GO HERE
echo $row['src'];
}
} else {
echo "no video results found";
}
CodePudding user response:
Added your HTML code in while loop:
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo '<li>
<a href="'.htmlspecialchars($row['src']).'"></a>
</li>';
}
} else {
echo "no video results found";
}
Outside the loop/without loop:
if ($result->num_rows > 0) {
$row = $result->fetch_assoc()
echo '<li><a href="'.htmlspecialchars($row['src']).'"></a></li>';
} else {
echo "no video results found";
}
CodePudding user response:
use the below code to create list. As I can see in your sql query, column name is video_src
if ($result->num_rows > 0) {
echo '<ul>';
// output data of each row
while($row = $result->fetch_assoc()) {
echo '<li><a href="'.htmlspecialchars($row['video_src']).'"></a></li>';
}
echo '</ul>';
}