Results 1 to 3 of 3

Thread: PHP and Cookies

  1. #1
    Giant Steps lo0ol's Avatar
    Join Date
    Nov 2003
    Location
    Pittsburgh
    Posts
    164

    PHP and Cookies

    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).
    I run good-tutorials.com.

    It's how I roll.

  2. #2
    Senior Member chromate's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    2,348
    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:

    PHP Code:

    setcookie 
    ("userPrefs[PerPage]""10");
    setcookie ("userPrefs[DisplayBy]""date"); 
    Obviously, "10" and "date" are just examples.

  3. #3
    Giant Steps lo0ol's Avatar
    Join Date
    Nov 2003
    Location
    Pittsburgh
    Posts
    164
    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.
    I run good-tutorials.com.

    It's how I roll.

Similar Threads

  1. Review: Professional PHP Programming
    By Chris in forum Books
    Replies: 6
    Last Post: 07-17-2013, 05:26 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •