我尝试引导滑动横幅,其中的其他文章可用于同一平台,但这没有帮助,因此我尝试使我的功能从一些文章和基本的PHP中学习。 我使用PDO是因为我比较新鲜,在学习阶段,这是我的入门课程。
我的脚本未按预期显示任何错误或结果,请在错误的地方以及如何解决此问题的问题上帮助我。
请帮助我。
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>