2011-10-23 19 views
-1

好吧,它在這裏! 我正在通過從MySQL數據庫獲取請求獲取圖像數組!並將其顯示爲幻燈片。它的工作!但我現在想要做的是,用Jquery顯示相同的圖像。通過Jquery顯示來自mysql的圖像?

<?php require("Connections/db_con.php"); ?> 
    <?php 
    $title = "slideshow"; 
    $id = mysql_real_escape_string((int)$_GET['id']); 
    $query_pic = "SELECT * FROM photos WHERE listing_id = $id "; 
    $result_pic = mysql_query($query_pic , $db_con); 
    $num_pic = mysql_num_rows($result_pic); 
    $row_pic = mysql_fetch_array($result_pic); 


    if($num_pic != 0) { 
     $image_set = array(); 
     $result = mysql_query("SELECT name FROM photos WHERE listing_id= $id"); 
     while($images = mysql_fetch_array($result)) { 
      array_push($image_set, $images['name']); 
     } 
    } 
    ?> 

    <html> 
    <head> 
    <title><>php echo $title; ?></title> 

    <link rel="stylesheet" href="stylesheets/styles/styles.css" media='all'/> 
    <link href="stylesheets/layout.css" media="all"/> 
    <link rel="stylesheet" href="stylesheets/styles/slideshow.css" media='all'/> 
    <script type='text/javascript'> 

    var photos = new Array(<?php echo "'".implode("','", $image_set)."'"; ?>); 
    var start = 0; // array index of first slide 
    var end  = <?php echo $num_pic -1; ?>; // array index of last slide 
    var current = start; 
    var doplay = true; // do not play show automatically 
    // skip to first slide 
    function first() { 
     current = 0; 
     change(); 
    } 

    // advance to next slide 
    function previous() { 
     current -= 1; 
     if(current < start) current = end; // skip to last slide 
     change(); 
    } 

    // go back to previous slide 
    function next() { 
     current += 1; 
     if(current > end) current = start; // skip to first slide 
     change(); 
    } 

    // skip to last slide 
    function last() { 
     current = end; 
     change(); 
    } 

    // change slide according to value of current 
    function change() { 
     document.photo.src = 'uploads/' + photos[current]; 
    } 

    // play automatic slideshow 
    function play() { 
     if(doplay == true) { 
      next(); 
      setTimeout(play, 2000); // call play() in 2.5 seconds 
     } 
    } 

    // pause slideshow 
    function pause() { 
     doplay = false; 
    } 

    </script> 
    </head> 

    <body> 

    <div id='container'> 


    <div class='form'> 

     <div id='photobox'> 

      <img name='photo' src='uploads/<?php echo $image_set[0]; ?>' alt=''/><br /><br /> 
      <?php // echo "Total " . $num_pic . " photo(s) found" ; ?> 

     </div> 


    </div> 

    </div> 
    </body> 
    </html> 

我怎麼能與jQuery的幻燈片,而不是一個我現在正在顯示它顯示相同的檢索到的圖像..我盡力,但我不能每次.. :(

+0

哪裏有關於jQuery的一點?我們需要知道該代碼出了什麼問題。 – ariefbayu

+0

有一個用於幻燈片放映的jquery循環插件 – Rafay

回答

1

此:

var photos = new Array(<?php echo "'".implode("','", $image_set)."'"; ?>); 

應該

var photos = <?php echo json_encode($image_set) ?>; 

json_encode將採取所有格式的護理/ escapin g的PHP數組轉換爲等效的Javascript語法,而沒有任何JS元字符在一個或多個文件名中導致JS語法錯誤的危險。

除此之外,究竟是什麼問題與jQuery的?你應該顯示你的jQuery代碼,因爲這是問題所在。向我們展示舊代碼毫無意義。