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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败