dongmozhui3805 2016-02-16 09:45
浏览 38
已采纳

如何从mysql数据库中的图像创建图像幻灯片

I have a mysqli database and form which allows me to store an id, name and photo. The path of the photo is set to an "images" folder on the server. I have a query which can

SELECT * FROM images WHERE name = $pagetitle.

This works absolutely fine, outside of the javascript slideshow. When i put a php command in the javascript where it is looking for which images to display, the js only shows 1 image, and not ALL images.

Any help would be appreciated, thanks.

The section of the code in question is below...

index.php

            <!-- Image Slide Show Start -->
  <div style="display: flex; justify-content: center;">
  <img align="middle" src="" name="slide" border=0 width=300 height=375>
                
<script>

<?php 
require('dbconnect.php');
$data = mysql_query("SELECT * FROM images WHERE name= '$pagetitle'");
$image = mysql_fetch_array( $data );



?>
//configure the paths of the images, plus corresponding target links
slideshowimages("<?php echo "/images/".$image['photo'] . ""?>")

//configure the speed of the slideshow, in miliseconds
var slideshowspeed=2000

var whichlink=0
var whichimage=0
function slideit(){
if (!document.images)
return
document.images.slide.src=slideimages[whichimage].src
whichlink=whichimage
if (whichimage<slideimages.length-1)
whichimage++
else
whichimage=0
setTimeout("slideit()",slideshowspeed)
}
slideit()


</script> </div><br><br>
                        <!-- Image Slide Show End -->

</div>
  • 写回答

3条回答 默认 最新

  • dseax40600 2016-03-14 14:46
    关注

    Try this:

    $sql = "SELECT * FROM images WHERE name= '$pagetitle'";
    $result = $conn->query($sql);
    
    $directory = '';
    while( $image = $result->fetch_assoc() )
        $directory .= ($directory != '' ? "," : '') . ('"/images/'.$image["photo"] . '"');
    
    
    
    // Check if it was successfull
        if($directory != '') {
    
        // if there are images for this page, run the javascript
        ?><script>
    
    
        //configure the paths of the images, plus corresponding target links            
        slideshowimages(<?php print $directory ?>)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题