为幻灯片显示实现下一个和后一个按钮

编程入门 行业动态 更新时间:2024-10-05 21:14:08
本文介绍了为幻灯片显示实现下一个和后一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试制作一个PHP幻灯片,我差不多完成了我只需要实现下一个和后面的按钮,我认为这些按钮很容易,但显然你不能在php中增加索引?

I'm trying to make a php slideshow and I'm almost done I just need to implement the next and back buttons which I thought were going to be easy, but apparently you can't increment indexes in php?

$sql = "SELECT pic_url FROM pic_info"; $result = $conn->query($sql); $count = 0; $dir = "dev2.matrix.msu.edu/~matrix.training/Holmberg_Dane/"; $source = "gallery.php"; if ($result->num_rows > 0) { // output data of each row $pic_array = array(); while ($row = $result->fetch_assoc()) { $pic_array[$count] = $row['pic_url']; $count++; } $index = 1; echo "<img src= ' $dir$pic_array[$index]' />"; echo "<a href= '$dir$pic_array[$index + 1]'>next</a>"; echo "<a href= '$dir$pic_array[$index - 1]'>back</a>"; } $conn->close(); ?>

推荐答案

我建议将网址放在一个数组中循环过来。

I would suggest to place the url's in an array and loop over them.

$urls = ['website/url/for/image/image.jpg', 'another/url/image.jpg']; foreach ($urls as $url) { echo 'a href="'.$url.'"> Click </a>'; }

这种方式肯定更具可读性。

It is definitely more readable that way.

更多推荐

为幻灯片显示实现下一个和后一个按钮

本文发布于:2023-11-28 04:21:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640936.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:幻灯片   按钮

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!