2011-10-23 2 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 배열을 동일한 자바 스크립트 구문으로 변환 할 수 있습니다. 하나 이상의 JS 메타 문자로 인해 JS 구문 오류가 발생할 수 있습니다.

그 외에도 jquery의 문제점은 무엇입니까? 문제가있는 곳에서 jquery 코드를 표시해야합니다. 우리에게 오래된 코드를 보여주는 것은 무의미합니다.

관련 문제