带有上一个和下一个功能的一张一张显示图像 [英] Display Images one by one with next and previous functionality

查看:110
本文介绍了带有上一个和下一个功能的一张一张显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将图像存储在一个单独的文件夹(图像)中,并创建了一个存储letterNumber的数据库,并且每个letterNumber都关联了多个图像.

I have stored images in a separate folder (images) and created a database that stores letterNumber and with each letterNumber several images are associated.

表(附件图像)如下.

letterNo, imageNo,    path,    height, width
   1         1      images/1a    700    630
   1         2      images/1b    710    628
   1         3      images/1c    705    630   `

同样,我有20个字母.

Likewise I have 20 letters.

现在在PHP中,我可以使用以下代码在网页上检索图像.

Now in PHP, I am able to retrive images on the web page with the following code.

$query="SELECT letterNo, width, height, path from annimages where letterNo=".$letterNumber;
$rs=mysql_query($query,$connection);
while ($row=mysql_fetch_array($rs))
{
    echo '<br/>';
    echo '<img src="' .$row['path'].'.jpg"' .' width="'.$row['width'].'" height="'.$row['height'].'" alt=Letter "'.$letterNumber.'" />'. '<br/>';
}

问题是:当我从导航栏中单击字母编号= 1时,它将显示与字母编号1相关联的所有图像.全部单击一次,但是我要一一显示带有上一个和下一个超链接的图像.

The problem is: when I click from navigation bar letter number = 1, it will display all images associated with letter number 1. All in one click but I want to show images one by one with next and previous hyperlink.

推荐答案

您仅使用1个过滤字段,需要同时使用(letteNo和imageNo)

You are only using 1 filtering field you need to use both (letteNo and imageNo)

$query="SELECT letterNo, width, height, path from annimages where letterNo=".$letterNumber." AND imageNo=".$imageNo." LIMIT 1";
$rs=mysql_query($query,$connection);
$row=mysql_fetch_array($rs)
echo '<br/>';
echo '<img src="'.$row['path'].'.jpg"'.'width="'.$row['width'].'"height="'.$row['height'].'" alt=Letter "'.$letterNumber.'" />'.'<br/>';

mysql LIMIT关键字限制返回多少行,但是,如果letterNo和imageNo的每个组合都与单个行相关,则不需要此行.虽然最好有一个限制,以防您没有捕获到所有的mysql注入攻击.

mysql LIMIT keyword limits how many rows are returned, though you dont need it if each combination of letterNo and imageNo relate to a single row. Though it is good to have a limit incase you dont catch all mysql injection attacks.

,每个上一个下一个链接都需要传递下一个letterNo和imageNo

and each previous next link will need to pass the next letterNo and imageNo

当然可以按照Madara Uchiha在其评论中建议的方式进行操作,并使用mysqli api,因为mysql api已贬值

And of course do as Madara Uchiha suggests in his comment and use mysqli api as the mysql api is depreciated

这篇关于带有上一个和下一个功能的一张一张显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆