本文介绍了为幻灯片显示实现下一个和后一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试制作一个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.
更多推荐
为幻灯片显示实现下一个和后一个按钮
发布评论