How to display a video player in a loop - php

 Let's see how to foreach videos from php driectly database .The following example will output the values of the given array ($video):



<?php

$db=mysqli_connect("localhost","username","password","database");

if (mysqli_connect_errno())

{

echo "Failed to connect to MySQL: " . mysqli_connect_error();

}


?>(code-box)

  • "password" or 'password'

<div class="row m-auto">


  <?php $video=mysqli_query($db,"SELECT * FROM `video`");

  while ($video_row=mysqli_fetch_array( $video)) { ?>

  <div class="col-lg-6 col-md-6 d-flex align-items-stretch" data-aos="fade-up" data-aos-delay="100">

    <div class="card">

     <iframe width="560" height="315" src="<?php echo $video_row['video']; ?>" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

      

      <div class="card-body">

        <h5 class="card-title"><a href=""><?php echo $video_row['name']; ?></a></h5>

        

      </div>

    </div>

  </div>

  

  <?php } ?>

  

</div>(code-box)


  •  <?php $video=mysqli_query($db,"SELECT * FROM `video`");  video table
  • change table values <?php echo $video_row['video']; ?>  
  • <?php echo $video_row['name']; ?>

Tags
Our website uses cookies to enhance your experience. Learn More
Accept !