PDA

View Full Version : PHP and Cookies



lo0ol
11-28-2003, 12:59 AM
So I've just trying to wrap my head around this for most of today. I have a page where I pull 10 records from the db, but I want the user to have more choice in this. I want to add a cookie so that the user can pick to display 10, 25, or 50 records at one time and how they want to display the records (by date descending, ascending, by other columns, etc).

I understand the mechanics of cookies and how to take the cookies and modify my SELECT queries that way, but what I'm trying to figure out is how to take the user's preferences and store them in an established cookie. For example,

Records per page: 10 | 25 | 50

where the user would click on an option and the new value would be reflected in the (perhaps new) cookie.

Heh, it's been such a long day I'm not sure what I'm asking anymore. :\ I guess basically I need a generalization of what needs to be done (actual code isn't necessary, etc).

chromate
11-28-2003, 04:52 AM
I'm not really sure what you're asking, as you said you already know how to set a cookie and read from them.

Are you looking to store an array of user preferences in the same cookie? If so use:




setcookie ("userPrefs[PerPage]", "10");
setcookie ("userPrefs[DisplayBy]", "date");



Obviously, "10" and "date" are just examples.

lo0ol
11-28-2003, 10:34 AM
Heh, I think I just needed a night to sleep on it. I was just confused about determining where and how to pick the option: either from the cookie or from a new value just submitted last page view. I think I figured it out though; I'll just pass a "?change=1" on the user-selected URLs and just do an if ($change = 1) { set new cookie } bit.