我有一个实验,它显示数据库中的随机图像,图像在屏幕上滚动显示3秒,暂停3秒钟,然后滚动屏幕3秒钟,然后我维护一个索引为“i”的数组,以便在客户端存储这些图像,如果“i”值增加,另一个图像会滚动到屏幕上,因为我正在显示来自数据库的图像,如果“i”递增,则应从数据库显示另一图像到屏幕上(意味着每次我递增时,应执行服务器端的代码)。谁能告诉我如何做到这一点?如何在客户端(java脚本)每次增加变量时在服务器端执行代码(php)
下面是示例代码,
//服务器端
$myQuery = "SELECT * from image WHERE img_id NOT IN (SELECT img_id from randomtrees where sid=".$sid.") ORDER BY rand() LIMIT 1";
$conn = mysql_connect("localhost","xxxxxx","xxxxxxxxxxxx");
mysql_select_db("database_name",$conn);
$result = mysql_query($myQuery);
$imagepath = 'path to the images folder which is in local host';
while ($row = mysql_fetch_array($result))
{
$img = $imagepath.$row['img_name'];
$id = $row['imageid'];
$img_id = $row['img_id'];
}
mysql_close($conn);
//客户端
slideimages[i++] = '<img src="<?php echo $img ?>" id="<?php echo $id?>" name="r_img"/>' ;
ajax !!!!!!!!!!! – Vishwanath 2010-12-11 07:34:19
@vishwanath - 这应该是一个答案;) – 2010-12-11 07:53:32