ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

SQL Update

August 22, 2008 4:11pm

Subscribe [3]
  • #1 / Aug 22, 2008 4:11pm

    Benjamin Katz

    20 posts

    Hello Everyone,

    Forgive me for my utter lack of PHP skills.  I’m in a bit of a bind that I can’t dig myself out of.

    What I need to do is to get a value from the database, increment it my one, and then save it back to the database.

    Using the Query module, I can use the following to retrieve the data I want:

    {exp:query sql="SELECT field_id_22 FROM exp_weblog_data WHERE entry_id = '{segment_3}' "}
    
    {field_id_22}
    
    {/exp:query}

    But, how do I go about doing the UPDATE query.  Of course, the Query module can’t handle that so I’ll have to use raw PHP.  Would anyone want to help me out with a sample query?

  • #2 / Aug 22, 2008 4:36pm

    Ingmar

    29245 posts

    Well, let’s see:

    <?php global $DB; $DB->query('UPDATE exp_weblog_data SET field_id_22 = (field_id_22 + 1)); ?>

    Not sure how it could be any easier 😊

  • #3 / Aug 22, 2008 8:41pm

    Benjamin Katz

    20 posts

    Well, let’s see:

    <?php global $DB; $DB->query('UPDATE exp_weblog_data SET field_id_22 = (field_id_22 + 1)); ?>

    Not sure how it could be any easier 😊

    Like I said, I’m PHP-challenged.  Have some pity :-p.
    For some reason, I did think it was going to be more complex though.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases