doujun7161 2014-02-16 09:10
浏览 33
已采纳

Nivo滑块+ php

I created a custom cms for a website and trying to make the nivo slider work with my db but im having issues with my while loop. im only storing the name of the image in the db and the image itself its in a folder, images are working somewhat but they appear on above the other the the actual slideshow is broken.

my guess is that the title id is breaking it but not sure on how to go from here. any help is appreciated

here is my code:

<div id='slider' class='nivoSlider'>
<?php 
$sql = 'SELECT * FROM slider';
$result = $db->query($sql) or die(mysqli_error());

 while($row = $result->fetch_assoc()){
    $slideshow = $row['slider_id']; 
    print"
        <img src='images/slider/".$row['image'].".jpg' alt='' title='#htmlcaption'>
        </div>
        <div id='htmlcaption' class='nivo-html-caption '>
        <span>".$row['title'] . "</span>    
        </div> ";
}

?>
<div id='preloader'></div>
</div>
  • 写回答

1条回答 默认 最新

  • dongxixian7803 2014-02-16 09:23
    关注
    while($row = $result->fetch_assoc()){
    $slideshow = $row['slider_id']; 
    print"
        <img src='images/slider/".$row['image'].".jpg' alt='' title'#htmlcaption'>
        </div> // ---------------> Here you are closing div slider
        <div id='htmlcaption' class='nivo-html-caption '>// ----> Error
        <span>".$row['title'] . "</span>    
        </div> ";
    

    }

    In while loop you are closing </div> without opening it,This cause broken slide show.In HTML syntax id's must be unique. So <div id='htmlcaption' class='nivo-html-caption '> so change this part.

    [Update] change print to

     print" <div class='some_wraper'>
            <img src='images/slider/".$row['image'].".jpg' alt='' title='#htmlcaption'>
            </div> // ---------------> Here now you are closing div some_wraper
            <div class='nivo-html-caption htmlcaption'>// ----> added new class htmlcaption
            <span>".$row['title'] . "</span>    
            </div> ";
    

    Update Fixed code

     <div id='slider' class='nivoSlider'>
        <?php 
    
        $sql = 'SELECT * FROM slider';
        $result = $db->query($sql) or die(mysqli_error());
    
         for($i = 0;$row = $result->fetch_assoc();$i++){
            $slideshow = $row['slider_id']; 
            echo "<img src='images/slider/".$row['image'].".jpg' alt='' title='htmlcaption_$i'>";                
            $tiles[$i]=$row['title'];        
        }
    
        ?>
        </div>        
       <?php //caption divs for slider
          for($i=0;$i<count($tiles);$i++) {
            echo "<div id='htmlcaption_$i' class='nivo-html-caption '>";      
                echo "<span>".$tiles[$i]."</span> </div>";
            }   
        ?>        
        <div id='preloader'></div>
        </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容