dongpeihui1051 2010-11-23 18:46
浏览 39
已采纳

PHP脚本变量表现奇怪

Script: (too large, didn't want to paste it and clutter this, sorry.)

http://pastebin.com/jhvgAqzj

Well, for some reason $p is acting very very weird, the $p is set to 1 and should add 1 to itself when the 'next' button is pressed. Inversely should subtract 1 from $p when the 'prev' button is pressed.

There are also 2 nested 'if' statements to prevent it from ever going over the max number or pictures, or under the min number of pictures.

$p is the variable used to display the picture according to its ID type.

For some reason, it will work until you get to picture 3, when you hit next, the variable jumps to 2. When you hit previous on 2, it jumps to 3.

This is very confusing but we laughed when we tested it.

Thanks for the help in advance!

  • 写回答

1条回答 默认 最新

  • dreamfly0514 2010-11-23 18:52
    关注

    When your page reloads, the value of $p is reset back to 1 every time. In order to remember which number $p was on the last post, you should use a session.

    session_start();
    $_SESSION['p'] = 1;
    

    Then, if the post value is set, you can reference your session to retrieve the value of p on your last page load.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺