从数据库中获取数据的无限循环

时间:2018-12-14 00:58:13

标签: php html mysql twitter-bootstrap function

你好,我已经完成了一个引导轮播,它从数据库中加载了图像和字幕,但是它只显示第一个图像,然后很快显示其余3个图像,并且幻灯片消失了。

<?php
 include 'header.php';
 require 'includes/dbh-inc.php';

 function make_query($conn)
 {
    $query = " SELECT * FROM notes ORDER BY id ASC ";
    $result = mysqli_query($conn,$query);
    return $result;
 }

 function make_slide_indicators($conn)
 {
    $output = '';
    $count = 0;
    $result = make_query($conn);
    while($row = mysqli_fetch_array($result))
    {
             if($count == 0)
             {
                 $output .= '<li data-target="#carouselExampleIndicators" data-slide-to="'.$count.'" class="active"></li>
   ';
             }
             else {
                        $output .= '
   <li data-target="#carouselExampleIndicators" data-slide-to="'.$count.'"></li>
   ';
             }
             $count = $count + 1 ;
    }

    return $output;
    make_slide_indicators($conn);
 }

 function make_slides($conn)
 {
    $output = '';
    $count = 0;
    $result = make_query($conn);
    while($row = mysqli_fetch_array($result))
    {
         if($count == 0)
         {
             $output .= '<div class="carousel-item active">';
         }
         else {
                $output .= '<div class="carousel-item">';
         }
         $output .= '<img src="images/notes/'.$row["image"].'" alt="'.$row["denomination"].'" style="width:100%; height:700px;"  /> 
         <div class="carousel-caption d-none d-md-block"> 
               <h3>'.$row['price'].'</h3>
          </div>
         ';
         $count = $count +1;
    }
     return $output;
 }
?>
<main> 



  <div class="container">
 <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
  <ol class="carousel-indicators">
   <?php echo make_slide_indicators($conn); ?>
  </ol>
  <div class="carousel-inner">
    <?php echo make_slides($conn); ?>
  </div>
  <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>
   </div>



</main>
<?php
include 'footer.php';
?>

如何创建无限循环以从数据库中获取信息,并且在显示最后一个图像时不停止工作?您能告诉我为什么其余图像显示得很快而不是默认设置的时间吗?

0 个答案:

没有答案