如何使图像滑块进入while循环 [英] how to make image slider into while loop

查看:70
本文介绍了如何使图像滑块进入while循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站从数据库中检索图像。该数据库有多个记录(ROWS)。我正在使用while循环来检索记录。每张唱片都有三张或四张图片。我想在while循环中使用水平图像滑块来检索所有记录。我在网上搜索。有很多滑块。但是没有任何东西在循环中。如果我将它们放入循环中则无法正常工作。请帮帮我一个。

I have a website retrieving images from database. The database has multiple records (ROWS). I am using while loop to retrieve the records. Every record having three or four images. I want to use a horizontal image slider into the while loop to retrieve all the records. I searched in the net. there are lot of slider. But nothing was in the loop. if I put them into the loop it was not working. please help me some one.

示例滑块: http://wowslider.com/automatic-jquery-slider-noir-squares-demo.html?affid=331J-S9

例如:

<?php
While($row=mysql_fetch_array($result)){

          **I need horizontal slider here**;
          }
?>


推荐答案

我(显然)不会给你写信给你整个小部件,但我很想给你所需的一切:

I (obviously) won't write you you the whole widget but I'm wailing to give you all you need:

首先,你需要PHP。我建议你学习PDO。它非常易于使用且非常安全:

First, you need PHP. I suggest you to learn PDO. It's very easy to use and pretty safe:

示例:

  <?php
     try {
       $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
       foreach($dbh->query('SELECT * from FOO') as $row) {
          print_r($row);
       }
      $dbh = null;
      } catch (PDOException $e) {
        print "Error!: " . $e->getMessage() . "<br/>";
       die();
      }
   ?>

PDO文档

然后,使用HTML和CSS来设置样式。

Then, use HTML and CSS to style the thing.

然后,您使用PHP生成HTML。

Then, you use PHP to generate the HTML.

然后,您将使用javascript setInterval

Then, you will use an javascript setInterval

setInterval 的示例

setInterval(function() {
  // Do something every 5 seconds
}, 5000);

如果您需要不同的ID,最简单的方法是:

If you need a different ID for each, the easiest way would be to do this:

   $counter = 0;
   foreach($foo as $bar){
     echo '<div id="slider'.$counter.'"></div>';
     //somecode
     $counter++;
   }

所以我不建议使用这个,你应该只给一个班级他们每个人都在jQuery中使用选择器同时启动它们

Tho, I do not recommand using this, you should just give one class to each of them and initiate them all at the same time in jQuery using the selector after

    $('.slider').myPlugin({
      //Plugins options
    })

这篇关于如何使图像滑块进入while循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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