Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    432
    Thanks
    6
    Thanked 3 Times in 3 Posts

    updating field when `field1`+`field2` = 'string'

    How do I update a counter field if field1 + a space + field2 equals $string.

    Code:
    UPDATE `counters` SET `counter1` = `counter1` + 1 WHERE `field1`.' '.`field2`` = '$string' LIMIT 1

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,100
    Thanks
    23
    Thanked 594 Times in 593 Posts
    I think I'd split the string into the field names and use
    UPDATE `counters` SET `counter1` = "counter1" + 1 WHERE `field1` = "first part of string" AND `field2`` = "Next part of string" LIMIT 1
    Please notice I removed the ticks from "counter1" and used double quotes. Tick are for column names.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    i think concat would work

    something like

    Code:
    UPDATE `counters` SET `counter1` = `counter1` + 1 WHERE CONCAT ( field1, field2 ) = '$string' LIMIT 1
    Last edited by Arcticwarrio; 03-18-2014 at 02:18 PM.
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  

    Posting Permissions

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