Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何为Mysql数据库中的图像实现旋转木马_Php_Mysql_Css_Jcarousel - Fatal编程技术网

Php 如何为Mysql数据库中的图像实现旋转木马

Php 如何为Mysql数据库中的图像实现旋转木马,php,mysql,css,jcarousel,Php,Mysql,Css,Jcarousel,我试图从Mysql数据库(特别是图像)中获取数据,然后将它们显示在旋转木马中,例如在amazon.com主页上 我是CSS的初学者。我没怎么用过 我已经看了一个,但我的不是一个图片列表在一起。我只是浏览了一下数据库中的数据 任何帮助都将不胜感激。从我在下面的评论中了解到,您的问题与CSS密切相关。 图像是垂直显示的,因为没有相邻浮动 代码如下: <html> <head> <title>Title</title>

我试图从Mysql数据库(特别是图像)中获取数据,然后将它们显示在旋转木马中,例如在amazon.com主页上

我是CSS的初学者。我没怎么用过

我已经看了一个,但我的不是一个图片列表在一起。我只是浏览了一下数据库中的数据


任何帮助都将不胜感激。

从我在下面的评论中了解到,您的问题与CSS密切相关。 图像是垂直显示的,因为
  • 没有相邻浮动

    代码如下:

    <html>
        <head>
            <title>Title</title>
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
            <script type="text/javascript" src="/path/to/jquery.jcarousel.js"></script>
            <style type="text/css">
            .jcarousel {position:relative; overflow:hidden;}
            .jcarousel ul {width: 20000em; position:relative; list-style:none; margin:0; padding:0;}
            .jcarousel li {float:left;}
            </style>
        </head>
        <body>
            <div class="jcarousel">
                <ul>
                    <li><img src="image1.jpg" alt="" /></li>
                    <li><img src="image2.jpg" alt="" /></li>
                </ul>
            </div>
            <script type="text/javascript">
                $(function(){
                    $('.jcarousel').jcarousel();
                });
            </script>
        </body>
    </html>
    
    
    标题
    .jcarousel{位置:相对;溢出:隐藏;}
    .jcarousel ul{宽度:20000em;位置:相对;列表样式:无;边距:0;填充:0;}
    .jcarousel li{float:left;}
    
    $(函数(){ $('.jcarousel').jcarousel(); });
    我知道这是一个老问题,但它可能对未来的用户有用。 下面是一个实现引导转盘以显示数据库中图像的简单解决方案:

    从数据库获取所有imageID并将其插入数组中(请注意,我将图像作为BLOB存储在数据库中:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
        <script src="jquery-3.1.0.min.js"></script>
        <script src="bootstrap/js/bootstrap.js"></script>
        <style>
            .myCarousel{
                height: 100%;
                width: 700px ;
                margin-top: 5px;
            }
            .slideimage{
    
                width: 700px;
                height: 320px !important;
            }
        </style>
    </head>
    <body>
    
    
    <?php
    
    include ('DBconnection.php');
    
    $ImageArray = array();
    
    $queryImages = "SELECT * FROM imagetable ";
    
    $result = mysqli_query($conn,$queryImages);
    
    if(mysqli_num_rows($result) >0){
    
        while ($row = mysqli_fetch_array($result)){
    
            $ImageArray[] = $row;
        }
    }
    
    ?>
                             <div id="myCarousel"  class="myCarousel carousel
                                        slideCarousel" data-ride="carousel" data-interval="5000" >
    
                                            <ol class="carousel-indicators">
    
                                            <?php
    
                                                // creating indicators - note that at least one must be set as active
    
                                                for($j=0;$j<count($ImageArray);$j++){
    
                                                        if($j==0){
                                                            echo ' <li data-target="#myCarousel" data-slide-to="'.$j.'" class="active"></li>';
    
                                                        }else{
    
                                                            echo ' <li data-target="#myCarousel" data-slide-to="'.$j.'"></li>';
    
                                                        }
                                                }
                                            ?>
    
    
                                            </ol>
                                            <div class="carousel-inner" role="listbox">
    
    
    
                                        <?php
    
                                              for($j=0;$j<count($ImageArray);$j++){
                                                     //If it is the first image set it as active
                                                      if($j==0){
                                                          echo '<div class="item active">
    
                                                                <!--Using image id and url  -->
    
                                                              <img class="slideimage" src="GetImageID.php?id=' .$ImageArray[$j]['ImageID'].'" /> 
    
                                                               <!-- or using base64_encode
    
                                                               <img src="data:image/jpeg;base64,'.base64_encode($ImageArray[$j]['Image']).'"/>
    
                                                               -->
                                                                </div>';
                                                      }
    
                                                      else{
                                                          echo '<div class="item">
                                                                  <img class="slideimage" src="GetImageID.php?id=' .$ImageArray[$j]['ImageID'].'" /> 
                                                                </div>';
                                                      }
                                              }
                                                ?>
    
    
                                            </div>
    
    
                                            <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
                                                <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
                                                <span class="sr-only">Previous</span>
                                            </a>
                                            <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
                                                <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
                                                <span class="sr-only">Next</span>
                                            </a>
                                        </div>
    </body>
    </html>
    

    你只想滚动文本还是图像。如果你只想滚动文本,那么在哪个方向水平还是垂直?你在MySQL中存储图像的方式是什么?我只想水平滚动图像。我只在MySQL中存储图像的路径,实际图像在我的项目文件夹中的一个名为images的文件夹中。我对php没有问题……我的挑战图片是垂直显示在我的网页上,而不是水平显示在旋转木马控件previous、left、slide等上。如果你对PHP没有问题,那么你不应该用“PHP”来标记问题。如果旋转木马垂直显示,而不是垂直显示,则问题是CSS、HTML或JS问题。请创建一个JSFIDLE,向我们显示当前代码:@user3231736您不应该使用JSFIDLE编写PHP代码。JSFIDLE仅用于HTML、CSS和Javascript。在您的情况下,您可以打开您正在谈论的网页,单击右键单击按钮并选择“查看页面源代码”,然后复制所有HTML代码并将其粘贴到JSFIDLE中。好的是,我检查了您的代码,您似乎忘记了包含jCarousel:)的CSS文件,因为根本没有CSS。我要编辑上面的答案。旋转木马有默认的css文件吗?没有,没有默认的css文件,但是你需要包括最少的css样式:我在上面的答案中共享了它们。
    include ('DBconnection.php');
    
    $imageid = $_GET['id'];
    
    $query = "Select Image from imagetable WHERE ImageID = '$imageid'";
    
    $result = mysqli_query($conn,$query);
    
    $row = mysqli_fetch_array($result);
    
    header("Content-type: image/jpeg");
    
    echo $row['Image'];