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