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

如何从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 ?>)
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dongzhi6146 2016-02-16 09:48

    your update query have syntax errors, use , between fields, also you must contain strings in 2 ' :

    $query = "UPDATE page_content SET PageTitle='$pageTitle',
    PageContent='$PageContent', PageContent2='$PageContent2' WHERE PageId='$PageId'";
    
    评论
    解决 无用
    打赏 举报
  • dshkmamau65777662 2016-02-16 09:52

    You have missed , between fields and '' around variables in your query.

    $sql = "UPDATE page_content SET PageTitle='$pageTitle', 
           PageContent='$PageContent', PageContent2='$PageContent2' 
           WHERE PageId='$PageId'";
    
    // check query executed successfully or get error
    $result = mysqli_query($conn,$sql) or die(mysqli_error($conn));
    

    OR

    $result = mysqli_query($sql) or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error(), E_USER_ERROR);
    

    Hope it will help you :)

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题