html - I want to create a dynamic carousel bootstrap banner in PHP
Get the solution ↓↓↓I try to bootstrap sliding banner where some others articles available to this same platform but it was not helpful so I try to make my function learn from some articles and basic PHP. I am using PDO because I am fresher and in learning stage this is my startup course.
My script not showing any error or result as I am expected, Please help me Where I am mistake and how to I fix this.
Please help me.
PHP
define('DB_USER',''); // DB Username
define('DB_PASS',''); // DB User Password
define('DB_NAME',''); // DB Name
//DB Connection an established
try {
$con = new PDO("mysql:host=".DB_HOST.";dbname=".DB_NAME,DB_USER, DB_PASS);
}
catch (PDOException $e) {
echo 'We are not able to connect with Database';
exit;
}
function make_query($con) {
$query = "SELECT * FROM `tb_banner` ORDER BY `ID` ASC";
$result = $con->prepare($query);
return $result;
}
function make_slide_indicators($con) {
$output = '';
$count = 0;
$result = make_query($con);
while($row = $result->fetch(PDO::FETCH_BOTH)) {
if($count == 0) {
$output .= '
<li data-target="#dynamic_slide_show" data-slide-to="'.$count.'" class="active"></li>
';
} else {
$output .= '
<li data-target="#dynamic_slide_show" data-slide-to="'.$count.'"></li>
';
}
$count = $count + 1;
}
return $output;
}
function make_slides($con) {
$output = '';
$count = 0;
$result = make_query($con);
while($row = $result->fetch(PDO::FETCH_BOTH)) {
if($count == 0) {
$output .= '<div class="item active">';
} else {
$output .= '<div class="item">';
}
$output .= '
<img src="'.$row["image"].'" alt="'.$row["banner_caption"].'" />
<div class="carousel-caption">
<h3>'.$row["banner_caption"].'</h3>
</div>
</div>
';
$count = $count + 1;
}
return $output;
}
HTML
<div class="page-slider">
<div id="carousel-example-generic" class="carousel slide carousel-slider">
<!-- Indicators -->
<ol class="carousel-indicators carousel-indicators-frontend">
<?php echo make_slide_indicators($con); ?>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<?php echo make_slides($con); ?>
<!-- Controls -->
<a class="left carousel-control carousel-control-shop carousel-control-frontend" href="#carousel-example-generic" role="button" data-slide="prev">
<i class="fa fa-angle-left" aria-hidden="true"></i>
</a>
<a class="right carousel-control carousel-control-shop carousel-control-frontend" href="#carousel-example-generic" role="button" data-slide="next">
<i class="fa fa-angle-right" aria-hidden="true"></i>
</a>
</div>
</div>
<?php exit(); ?>
</div>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: using $this when not in object context
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
About the technologies asked in this question
PHP
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
MySQL
DBMS is a database management system. It is designed to change, search, add and delete information in the database. There are many DBMSs designed for similar purposes with different features. One of the most popular is MySQL.
It is a software tool designed to work with relational SQL databases. It is easy to learn even for site owners who are not professional programmers or administrators. MySQL DBMS also allows you to export and import data, which is convenient when moving large amounts of information.
https://www.mysql.com/
Bootstrap
Bootstrap is not exclusively a CSS framework, but its most popular features are CSS-centric. These include a powerful grid, icons, buttons, map components, navigation bars, and more.
https://getbootstrap.com/
HTML
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to programmierfrage.com
programmierfrage.com is a question and answer site for professional web developers, programming enthusiasts and website builders. Site created and operated by the community. Together with you, we create a free library of detailed answers to any question on programming, web development, website creation and website administration.
Get answers to specific questions
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Help Others Solve Their Issues
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.