SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help with method to build dynamic query

    I am trying to construct a dynamic update query based on which values passed to the update function are not null.

    I have this function
    PHP Code:
    function update_person($ID$FName$LName$Middle$SocNum$Salutation$Suffix$Degree
    and the plan is that if I call it like this
    PHP Code:
    update_person($ID,,,,,,"PHD"); 
    That my query will only update the persons degree to phd where they have the sent ID value. I cannot figure out a way to get around the last comma at the end of the string.

    For instance if I just added them up by cacatenating strings I would have to know which one was the last one to be updated so that I did not place a , at the end of the string.

    Anyone found a good way to work around this?
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."

  2. #2
    public static void brain Gybbyl's Avatar
    Join Date
    Jun 2002
    Location
    Montana, USA
    Posts
    647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just move the degree parameter over to the second spot, and set default values for all of the parameters after it. Unless you are planning on making all of them potentially dynamic, then, I probably wouldn't use a function, but a series of switches or something.
    Ryan

  3. #3
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea, the idea is that any combo can be sent. Only the ID is required to identify the record, the rest may or may not be needed to be updated which is why I was planning on trying to make some way to create a completely dynamic query. I only used the degree line as a simple example.

    I might just go ahead and grab the current values first and then use them for values that were not passed to the function so that I update all of the fields.
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."


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
  •