【问题标题】:How to make dynamic slideshow using php, mysql, css and html?如何使用 php、mysql、css 和 html 制作动态幻灯片?
【发布时间】:2015-05-29 01:52:06
【问题描述】:

我想用 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 } ?>

【问题讨论】:

  • 是的,上面的代码错误
  • 在你的问题中包含错误:) @Sufi
  • 我的意思是,该代码没有显示图像但没有任何错误消息。

标签: php html mysql css


【解决方案1】:

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

将您的任何&lt;img&gt;s 替换为

<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_* 函数。

【讨论】:

  • 其实我不想使用循环,我想在数据库中使用id来显示/显示带有html标签的网页中的图像。
  • 好的,然后是&lt;img src="getImage.php?id=2" alt="" width="640" border="320"/&gt;
  • Iko,getImage.php 的语法是什么?这是获取图片的链接吗?
  • @Sufi:您需要编写 getImage.php 代码以从数据库中获取相应的图像数据
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-13
  • 1970-01-01
  • 2018-02-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多