简体   繁体   中英

PHP session not updating variable

I'm building an image slider where images are loaded from my database and displayed inside a php page.

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.

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. I can only browse image no. 1 and image no. 2

I believe the code is correct, but I'm afraid there's something missing about how PHP sessions works, can you confirm it?

//

session_start() must be the second thing on your page after <?php . HTML tags must be placed after it or the session will not be started.

You do not need to use Session to maintain the pagination, instead Keep the pagination status inside Next, Prev html buttons. I could see some better pagination logic here at:

Simple PHP Pagination script

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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