How can I keep a set of data during several calls to the server in PHP?
I am developing a really simple PHP application to display pictures on the web. My application is composed by a Database with two tables Image and Categories, some simple business logic and the UI.
In the UI, when the user loads the page for the first time, has a picture (randomly taken) the possibility to browse the images with left/right arrows and the possibility to choose a specific category (one picture belongs at the most to one category).
My issue is in the browsing mechanism. If I browse the image without selecting a category everything is fine. If I select a categor开发者_如何学编程y the website correctly displays all the thumbnails of the images belonging to that category (easy query).
However if I click on one picture (it load in another page) and then navigate with the arrows the website browses all the pictures and not those beloning to the selected category. I would like instead to browse just pics in the selected category.
How can I implement this mechanism? I alwasy pass Category_Id and Image_Id (null for all pictures) to the server function but I always lose the state of the iterator in the variable containing the query elements. How can I solve this problem?
Solutions with code sample are appreciated, however it is enough to propose an implementation logic.
Thanks
Francesco
I did something similar a while back.
Assuming that you want your images displayed in image_id order you could do the following.
On the "next" link, you make a call to your PHP script with parameters that identify the category and the id and the direction you want to move.. eg
myserver.com/myapp/images.php?action=next&cat=holidaypics&image_id=111
Then you can do a query to find the next highest image_id with the same category by doing something like "select min(image_id) from images where category_id="holidaypics" and image_id > 111"
If you're going in reverse you'd change the action to "prev" and do a query like this...
"select max(image_id) from images where category_id="holidaypics" and image_id < 111"
Does that help?
Use sessions http://ru2.php.net/manual/en/book.session.php
or pass all variables your need every time you ask server.
Consider Ajax to load your container with images of a particular category.
It is as simple as saying HI
精彩评论