duanjiong5023 2012-08-08 08:34
浏览 59
已采纳

从mysql数据库动态加载图像到jquery滑块

I have written a web application that involves having users upload pictures to the site. On the homepage, I dynamically show the newest pictures/items uploaded in PHP, limiting it to ten. However, the page looks so static and I have searched on Google, bing, ask, yahoo, etc for days now and haven't had any answers.

I have written the code to store store the images, and get them from the db. The images are shown on the homepage, and the only thing i have left to do is load it in a slider.

$sql = mysql_query("SELECT * FROM items ORDER BY item_date_added DESC LIMIT 10")or die(mysql_error());
while($row = mysql_fetch_array($sql)) {
    //$user_id = $row['user_id'];
    $item_name = $row['item_name'];
    $item_id = $row['item_id'];

    $check_pic = "users/$item_name.jpg";

    if (file_exists($check_pic)) {
        $show_pic = "<img src=\"users/$item_name.jpg\" width=\"100px\" height=\"100px\" border=\"5\" id='img'/>";

        //$user_pic3 = "<img src=\"users/$rid/image01.jpg\" width=\"50px\" height=\"50px\" border=\"1\" />";
        //$MemberDisplayList .= '<a href="profile2/index.php?id=' . $rid . '">' . $user_pic3 . '</a>';
        $i++;
        $show_new_items .= "<a href='item_view?item_id=$item_id&&session_item=$item_id'>$show_pic</a>";
    }
    $newly_listed_names .= " <a href='item_view?item_id=$item_id&&session_item=$item_id'> $item_name </a> | ";
}

///////// END SHOW NEWLY ADDED ITEMS ///////////////////////////////////////////////////

the newly added items in echoed in a div in the body.

Can anyone help me please! it's been bothering me for a while now. Thanks.

  • 写回答

2条回答 默认 最新

  • doushibu2453 2012-08-08 09:05
    关注

    To use Nivo, you need to generate html that looks something like this... (Download the nivo demo and open up the demo.html for the full source).

    So all you need to do is output your images in a loop inside the slider div.

    <div id="wrapper">
        <div class="slider-wrapper theme-default">
            <div id="slider" class="nivoSlider">
        <?php
            while($row = mysql_fetch_array($sql)){
                $item_name = $row['item_name'];
                $item_id = $row['item_id'];
                $check_pic = "users/$item_name.jpg";
                if (file_exists($check_pic)) {
                    print "<img src=\"users/$item_name.jpg\"/>";
                    $i++;
                }
            }
        ?>
                <img src="images/2.jpg" data-thumb="images/2.jpg" alt=""/>
            </div>
        </div>
    </div>
    
    <script type="text/javascript" src="scripts/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="../jquery.nivo.slider.js"></script>
    <script type="text/javascript">
    $(window).load(function() {
        $('#slider').nivoSlider();
    });
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘