简体   繁体   English

PHP会话未更新变量

[英]PHP session not updating variable

I'm building an image slider where images are loaded from my database and displayed inside a php page. 我正在建立一个图像滑块,从数据库中加载图像并显示在php页面中。

There's a session variable, "number", to remember what is the current database row, in this way I can easily move to next or previous image. 有一个会话变量“ number”可以记住当前数据库行是什么,这样我就可以轻松移至下一个或上一个映像。

Initially the page was working perfectly, but now when I press on "Next" button to increase session number and move to next page, it remains stuck to "2" and doesn't allow me to read other pages, even if there are multiple ones. 最初,该页面运行良好,但是现在,当我按下“下一步”按钮以增加会话号并移至下一页时,它仍然停留在“ 2”,即使有多个页面,我也无法阅读其他页面那些。 I can only browse image no. 我只能浏览图像编号。 1 and image no. 1和图像编号。 2 2

I believe the code is correct, but I'm afraid there's something missing about how PHP sessions works, can you confirm it? 我相信代码是正确的,但是恐怕PHP会话的工作方式还缺少一些内容,您可以确认吗?

// //

session_start() must be the second thing on your page after <?php . session_start()必须是<?php之后的第二页。 HTML tags must be placed after it or the session will not be started. 必须在其后放置HTML标记,否则将无法启动会话。

You do not need to use Session to maintain the pagination, instead Keep the pagination status inside Next, Prev html buttons. 您无需使用Session来维护分页,而是将分页状态保留在Next,Prev html按钮内。 I could see some better pagination logic here at: 我可以在以下位置看到一些更好的分页逻辑:

Simple PHP Pagination script 简单的PHP分页脚本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM