如何使用php、mysql、css和html制作动态幻灯片


How to make dynamic slideshow using php, mysql, css and html?

我想用css和HTML制作动态幻灯片。图像将由tb_Image中的id拍摄。

id int
image_name varchar (100)
image_path (100)

如何使用php、mysql、css和html制作动态幻灯片?或者可以通过id获取图像?

include "connnection.php";
$result = mysql_query("select * from slider");
?> 
    <div class="accordian">
    <?php 
        $i=1;
    while($row = mysql_fetch_array($result)){
    ?>
            <ul>
                <li>
                    <div class="image_title">
                    </div>
                    <a href="#">
                    <img src="../img/<?php echo $i;?>.jpg" alt="" width="640" border="320"/> //I tried use this codes but it's error
                    </a>
                </li>
                <li>
                    <div class="image_title">
                        <a href="#">Slide 2</a>
                    </div>
                    <a href="#">
                        <img src="img/<?php echo $_GET['id']=2;?>.jpg" alt="" width="640" border="320"/>
                    </a>
                </li>
                <li>
                    <div class="image_title">
                        <a href="#">Slide 3</a>
                    </div>
                    <a href="#">
                        <img src="img/3.jpg"/>
                    </a>
                </li>
                <li>
                    <div class="image_title">
                        <a href="#">Slide 4</a>
                    </div>
                    <a href="#">
                        <img src="img/4.jpg"/>
                    </a>
                </li>
                <li>
                    <div class="image_title">
                        <a href="#">Slide 5</a>
                    </div>
                    <a href="#">
                        <img src="img/5.jpg"/>
                    </a>
                </li>
            </ul>
            <?php } ?>

不知道从查询中得到了什么,下面是一个猜测:

用替换任何<img>

<img src="../img/<?php echo $row['id']?>.jpg" alt="" width="640" border="320"/>

为了"调试"你的数据,你可以用代替while循环

while($row = mysql_fetch_array($result)){
  print_r($row);
}

这将打印出在每一行中找到的任何数据。

您可能还想用mysqliPDO替换不推荐使用的mysql_*函数。