Nivo滑杆+ PHP [英] Nivo slider + php

查看:98
本文介绍了Nivo滑杆+ PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为网站创建了一个自定义cms,并尝试使nivo滑块与我的数据库一起工作,但是我的while循环出现问题. 我只将图像的名称存储在数据库中,并将图像本身存储在一个文件夹中,图像虽然工作正常,但它们出现在另一个上方,实际的幻灯片显示已损坏.

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.

我的猜测是标题ID打破了它,但不确定如何从这里开始.感谢您的帮助

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

这是我的代码:

<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>

推荐答案

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> ";

}

在while循环中,您关闭了</div>却没有打开它,这会导致幻灯片放映失败.在HTML语法中,id必须是唯一的.因此,<div id='htmlcaption' class='nivo-html-caption '>更改此部分.

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.

[更新] 将打印更改为

 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> ";

更新 固定代码

 <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>

这篇关于Nivo滑杆+ PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆