How to skip value if it is already inserted in database ?

Discussion in 'Programming' started by node/1, Sep 3, 2010.

  1. #1
    I have a bot which was written for wordpress so I don't want to insert post if its title already inserted in database how can I do that ?
     
    node/1, Sep 3, 2010 IP
  2. Vicbowling

    Vicbowling Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Essentially - select title from your_table where title = new_title

    You can either do that statement - and check in php if a result is returned - if there is a result, the title exists, if there isn't a result you submit it...
    or you can use an if in your mysql statement -
    - for more info lookup mysql control flow functions
    - probably better design to do it from mysql.
     
    Vicbowling, Sep 3, 2010 IP
  3. node/1

    node/1 Guest

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hello @Vicbowling thank you for your tips it was really helpful I wonder another side of inserting data is the value case sensetive ? I may have title that are upper case and lower case
     
    node/1, Sep 3, 2010 IP
  4. HuggyEssex

    HuggyEssex Member

    Messages:
    297
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    45
    #4
    Store them all in the database as lower case, using strtolower($var); when your displaying them you can make them upper case with strtoupper($var); or ucwords($var); which will make each letter capital on each word.

    There's lot's more information on this here,

    http://php.net/manual/en/book.strings.php

    Kind regards,

    Glen Hughes
     
    HuggyEssex, Sep 3, 2010 IP
  5. node/1

    node/1 Guest

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Excellent Thank you !
     
    node/1, Sep 3, 2010 IP