I have divided this tutorial into few steps to make it easier to understand its working.
- Create a Database, Table
- Create a Database Connection
- Create an Index File
1. Create a Database, Table and
To create a table run the following query.
CREATE TABLE IF NOT EXISTS `products` (`id` int(10) NOT NULL AUTO_INCREMENT,`title` varchar(250) NOT NULL,`link` varchar(250) NOT NULL,`status` varchar(250) NOT NULL,PRIMARY KEY (`id`),
Table Created
2. Create a Database Connection
Create a displayvideos.php file and paste the following database connection in it. Make sure that you update these credentials with your database credentials.
PHP mysqli connect() Function
<?php
$db=mysqli_connect("localhost","root","","displayvideos");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
Create an Index File
Create an index.php file and paste the following script in the beginning of your file.
Display code php
<div class="row">
<?php $video=mysqli_query($db,"SELECT * FROM `video`");
while ($video_row=mysqli_fetch_array( $video)) { ?>
<div class="col-md-12">
<iframe width="50%" height="315" src="<?php echo $video_row['link']; ?>" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<h3 class="single-item-description"><?php echo $video_row['title']; ?></h3>
</div>
<?php } ?>


0 Comments