SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a page where I can assign a person to multiple categories, and if that person is the default person of that category or not. It is very similar to Kevin's Building a Database-Driven Web Site Using PHP and MySQL example of how to add an author's joke to certain categories, only with the added feature of being able to say that that author is the default author of a certain category. This is setup with checkboxes on the form as follows:

    Group: select[x]--default[x]

    I find it very easy to setup a new person to a group. It is no different than in Kevin's example. Where I'm running into difficulty is if I have to edit this persons profile.

    The question is this: How do I delete the person from a category or unassign him as the default when, in an edit profile screen, I uncheck him from a category or as the default?

    Remember the category names are dynamically generated and I'm using a variable variable to ADD them to the DB.

    Now I want to state that I have gotten this to work by deleting all of the persons entries to category table in the DB after the form has been submitted, and then re-adding him to the DB according to what is checked in the form. But I can't help but feel that is very inefficient. I'm querying and deleting and writing to the database a lot in a short period of time that, I would think, put a strain on the server. So...what would be a better way of accomplishing this task?

    If you need further explanation or a snip of my code, just let me know.
    Joe Eliason
    Just a dog learnin' PHP from cat.

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Sounds like you're doing it just fine, HotDog. Indeed, you could write a more complex script that compared the old checked values to the new ones and produced queries to make only the required changes, but in an administration script such complex code is wasted.

    Efficiency is most important in tasks that will be done frequently and, unless I'm mistaken, modifying what categories an item belongs to is not something you're likely to be doing constantly.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the input kev. Like I said, it works the way I have it, I was just wondering if there was a better way of doing it. But I'll just leave it the way it is since, as you said, it won't be very often where a person will switch catigories and such.

    Ruff!
    Joe Eliason
    Just a dog learnin' PHP from cat.


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
  •