1
我正在编写脚本以在我的网站上显示图像。图像存储在服务器上,源(路径)位于mySQL数据库中。我希望能够通过调用我已经做过的两个PHP函数来移动到下一个(或之前的图片)。到目前为止,我已经写的代码是:移动到下一图像的脚本
<?php
require "db_connection.php";
$query="SELECT source FROM photos";
$result=mysql_query($query);
$count=0;
$numberofpics=mysql_num_rows($result);
$image=mysql_result($result, $count, "source");
$num=1;
function slideshowForward() {
$num=$num+1;
if($num==($numberofpics+1)) {
$num=1;
}
$count=$count+1;
$image=mysql_result($result, $count, "source");
}
function slideshowBack() {
$num=$num-1;
if ($num==0) {
$num=$numberofpics;
}
$count=$count-1;
$image=mysql_result($result, $count, "source");
}
?>
的HTML部分,显示的图像是:
<!-- FORWARD AND BACK FUNCTIONS-->
<a class="back" href="http://mywebsite.com/discoverandrank.php?function=slideshowBack()"> <img src="graphics/back.png"/></a>
<a class="next" href="http://mywebsite.com/discoverandrank.php? function=slideshowForward()"><img src="graphics/forward.png"/></a>
<!--DISPLAY MIDDLE PHOTO-->
<div id="thepics">
<img src="http://www.mywebsite.com/<?php echo $image; ?>" name="mypic" border=0 height="300" width="500"></img>
</div>
我敢肯定的是,PHP脚本将递增/递减当前的计数为图像,但我认为这个问题可能是因为当图像数量增加时,html(特别是img src =“....”)部分不会被重新评估?
“?”后面的短语是什么?参考? (op = next&current = 10) – Nochbag 2011-12-27 22:12:52
op = next&current = 10意味着在你的php中,你可以将它们视为$ _GET [“op”]和$ _GET [“current”],那么你可以做类似if(isset ($ _GET [“op”])&&($ _GET [“op”] ==“next”){calculateNext();} – guiman 2011-12-28 17:06:07