2

我制作了一些代码行以在每次单击后递归更改图像但不起作用。当我单击第一个拇指时,该代码仅显示目录的最后一个图像......知道为什么吗?这是注释的代码:

<?php
//DB connection
include ("conn.inc");
// parameter for DB query   
$rif_pippo = "id_pippo"; 
// DB query
$query = mysql_query("SELECT * FROM pippo WHERE rif_pippo ='$rif_pippo'"); 
$result = mysql_num_rows($query);
$row = mysql_fetch_assoc($query);
// div in wich there's IMG SRC to recursively change
echo "<div><img id='change_this'src='images/medium/".$row['rif_pippo']."/".$row['rif_pippo]."_medium01.jpg' alt='' /></div>";
// thumbnails list
echo "<ul>";
// count how many images there are in directory
$images = glob('images/pippo/medium/'.$row[rif_pippo].'/*.jpg');
$images_number= count($images);
// cicle to show all directory's thumbnails
for ($i=1; $i<=$images_number; $i++) {
// I change the images prefix adding a 0 for images betweeen 0 and 9
if ($i<=9) {$v='0'.$i;}
else if ($i>=10) {$v=$i;};
// JQUERY script 
echo "<script type='text/javascript'>";
echo "$('#id_box_foto').click(function() {";
echo "$('#change_this').attr('src','images/medium/".$row['rif_pippo']."/".$row['rif_pippo']."_medium".$v.".jpg').stop(true,true).hide().fadeIn('slow');";
echo "return false";
echo "});";
echo "</script>";

// thumbnail to change IMG SRC
echo "<li><a href='#id_box_foto' id='id_box_foto'><img class='foto' style='border:0px;' src='images/thumbnails/".$row['rif_pippo']."/".$row['rif_pippo']."_thumb".$v.".jpg' alt='' /></a></li>";
}

echo "</ul>";

?>
4

1 回答 1

1

The issue is that you are writing a jquery script for every image. When #id_box_foto is clicked all of these scripts run, the one that runs last is the last image.

To fix this you will probably want to write only one script with a list of the ids. When this is called it sets the image to be the next id in the list.

于 2012-12-13T00:01:04.127 回答