Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2004
    Location
    Seattle, WA
    Posts
    601

    Unanswered: help with update query logic

    My form is to update a record, and it has two combo boxes. These you are able to select a program and a item associated with that program, like a task associated with that program. for example, a car manufacturer then a model. I have three text area boxes with details. Since I don't have a handle on ajax yet, the boxes have a place holder value of "Type a new blah or just delete this" where blah is a change to that field, so the old value isn't totally important. Each blah is diffent, so just change blah to another word for the other two text areas.

    I need help with putting a query together that looks at each text area and if it isn't that specified value, update that record. I am thinking something like:

    Code:
    UPDATE myTable
       CASE
         WHEN (($textarea1 !== "Type a new blah or just delete this") OR ($textarea1 !== NULL)
           THEN SET myField = $textarea1 
       END CASE
       CASE
         WHEN (($textarea2 !== "Type a new blah2 or just delete this") OR ($textarea1 !== NULL)
           THEN SET myField2 = $textarea12
       END CASE
       CASE
         WHEN (($textarea3 !== "Type a new blah3 or just delete this") OR ($textarea1 !== NULL)
           THEN SET myField3 = $textarea3 
       END CASE
       WHERE someField1 = $myCombo1 AND someField2 = $myCombo2;
    Ryan
    My Blog

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    UPDATE myTable 
       SET myField = $textarea1 
     WHERE someField1 = $myCombo1 
       AND someField2 = $myCombo2
       AND $textarea1 <> 'Type a new blah or just delete this"'
    ;
    UPDATE myTable 
       SET myField = $textarea2 
     WHERE someField1 = $myCombo1 
       AND someField2 = $myCombo2
       AND $textarea2 <> 'Type a new blah or just delete this"'
    ;
    UPDATE myTable 
       SET myField = $textarea3 
     WHERE someField1 = $myCombo1 
       AND someField2 = $myCombo2
       AND $textarea3 <> 'Type a new blah or just delete this"'
    ;
    of course, this doesn't make much sense -- why would you hvae three different form textareas all updating the same column on the same row

    but those were your specs

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jun 2004
    Location
    Seattle, WA
    Posts
    601
    Rudy, Each textarea isn't updating the same column on the same row (myField1, myField2, myField3). Each textarea is updating a different column in the same row.
    Think of the two combos as fixed points. The text areas can be changed. I could just use one combo, but the second gives more security.

    Thanks.
    Ryan
    My Blog

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    ah, i see

    okay, adjust my code so that each textarea updates the correct field

    thanks

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Jun 2004
    Location
    Seattle, WA
    Posts
    601
    well of course. That is one narly statement.
    Ryan
    My Blog

Posting Permissions

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