Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
下一个图像使用PHP_Php_Html - Fatal编程技术网

下一个图像使用PHP

下一个图像使用PHP,php,html,Php,Html,我有基于表格的图像库,如下所示: <table id="gallery"> <tr> <td><a href="largeimg.php?imageID=images/seascape/medium.Vietnam 19.jpg&caption= Vietnam, Cat Ba Island, Vietnam - 2015"><img src="images/seascape/thumb.Vietnam 19.jpg" height

我有基于表格的图像库,如下所示:

<table id="gallery"> 
<tr>
<td><a href="largeimg.php?imageID=images/seascape/medium.Vietnam 19.jpg&caption= Vietnam, Cat Ba Island, Vietnam - 2015"><img src="images/seascape/thumb.Vietnam 19.jpg" height="75" ></a></td>
<td><a href="largeimg.php?imageID=images/seascape/medium.Vietnam 17.jpg&caption= Vietnam, Cat Ba Island, Vietnam - 2015"><img src="images/seascape/thumb.Vietnam 17.jpg" height="75" ></a></td>
<td><a href="largeimg.php?imageID=images/seascape/medium.Vietnam 14.jpg&caption= Vietnam, Cat Ba Island, Vietnam - 2015"><img src="images/seascape/thumb.Vietnam 14.jpg" height="75" ></a></td>
</tr>

然后在页面largeimg.php上,我使用它检索图像id和标题以显示所选图像:

<figure>
<img src="<?php echo $_GET['imageID']; ?>">
<figcaption class="big"><?php echo $_GET['caption']; ?></figcaption>
</figure>

">

有没有一种简单的方法可以使用PHP添加使用“上一页”和“下一页”按钮浏览图库的功能?

您要做的事情需要使用客户端技术。请记住,PHP是在服务器端解释的,因此您需要使用客户端语言,如Javascript(我建议使用jQuery)来实现这一点。您还需要考虑对图像进行分页,因为一次加载所有图像可能会带来巨大的负载

对于你正在尝试做的事情,我甚至会研究Angular js。如果你的项目值得你花时间,我肯定会考虑使用Angular作为图像库,但这当然只是我个人的观点


祝你好运。

你要求做的事情需要使用客户端技术。记住PHP是服务器端解释的,因此你需要使用客户端语言,如Javascript(我建议使用jQuery)为了实现这一点,您还需要考虑对图像进行分页,因为一次加载所有图像可能会带来巨大的负载

对于你正在尝试做的事情,我甚至会研究Angular js。如果你的项目值得你花时间,我肯定会考虑使用Angular作为图像库,但这当然只是我个人的观点

祝你好运。

是的,这是可能的。 例如,您有名为“图库”和“照片”的表。 您的照片名称为1.png、2.png、3.png,所有这些图片都属于一个图库,其id为2

像这样控制当前图像索引

if(isset($_GET["i"])){
    $i = intval($_GET["i"]);
    if($i<0){
      $i=0;
    }
}else{
    $i = 0;
} 
$next = $i+1;
$prev = $i-1;
根据此结果,将当前照片名称存储在如下数组中

$curr_photo = $mysqli->query("select name from photos where gallery_id = 2 limit =1 offset=".$i);
<a href="gallery.php?id=2&i=<?php echo $prev;?>">Prev</a>
<a href="gallery.php?id=2&i=<?php echo $next;?>">Next</a>
最后,创建下一个和上一个照片链接,如下所示

$curr_photo = $mysqli->query("select name from photos where gallery_id = 2 limit =1 offset=".$i);
<a href="gallery.php?id=2&i=<?php echo $prev;?>">Prev</a>
<a href="gallery.php?id=2&i=<?php echo $next;?>">Next</a>

是的,这是可能的。 例如,您有名为“图库”和“照片”的表。 您的照片名称为1.png、2.png、3.png,所有这些图片都属于一个图库,其id为2

像这样控制当前图像索引

if(isset($_GET["i"])){
    $i = intval($_GET["i"]);
    if($i<0){
      $i=0;
    }
}else{
    $i = 0;
} 
$next = $i+1;
$prev = $i-1;
根据此结果,将当前照片名称存储在如下数组中

$curr_photo = $mysqli->query("select name from photos where gallery_id = 2 limit =1 offset=".$i);
<a href="gallery.php?id=2&i=<?php echo $prev;?>">Prev</a>
<a href="gallery.php?id=2&i=<?php echo $next;?>">Next</a>
最后,创建下一个和上一个照片链接,如下所示

$curr_photo = $mysqli->query("select name from photos where gallery_id = 2 limit =1 offset=".$i);
<a href="gallery.php?id=2&i=<?php echo $prev;?>">Prev</a>
<a href="gallery.php?id=2&i=<?php echo $next;?>">Next</a>


查看分页或jquery处理服务器端代码(如PHP)的唯一方法是在下一个和上一个命令中重新加载页面。您需要查询字符串之类的内容(即
?img=1
)附加到url的末尾。然后根据操作增加或减少数字,并重新加载整个页面。这样肯定会影响性能。简而言之,在客户端使用JavaScript…查看分页或jquery。使用服务器端代码(如PHP)的唯一方法是在下一个页面上重新加载页面d以前的命令。您需要将查询字符串(即,
?img=1
)之类的内容附加到url的末尾。然后根据操作增加或减少数字,并重新加载整个页面。这样肯定会影响性能。简言之,在客户端使用JavaScript。。。