www.webdeveloper.com
Results 1 to 3 of 3

Thread: Adding Number To Database Column Value

Hybrid View

  1. #1
    Join Date
    Aug 2008
    Posts
    31

    Adding Number To Database Column Value

    I'm trying to add a number to the value of a column in my db but I'm having no such luck in doing this. Heres my code:

    PHP Code:
    <?php
        session_start
    ();
        
        require_once(
    '../config.php');
        
        
    $link mysql_connect(DB_HOSTDB_USERDB_PASSWORD);
        if(!
    $link) {
            die(
    'Error: '.mysql_error ());
        }
        
        
    $db mysql_select_db(DB_DATABASE);
        if(!
    $db) {
            die(
    'Error: '.mysql_error ());
        }
        
            
    $result mysql_query("SELECT * FROM members") or die ('Error: '.mysql_error ());

    while(
    $row mysql_fetch_array($result))
      {
    $points $row['points'];
    $points += 7;
      }

    $result mysql_query("UPDATE members SET points=$points WHERE ia11='North Carolina'"
    or die(
    mysql_error());  

            
    mysql_close($link);
    ?>
    I just want to add 7 to the current value.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    Quote Originally Posted by bholtiphone View Post
    ...
    I just want to add 7 to the current value.
    You could do it in one query:
    Code:
    UPDATE members SET points = points + 7 WHERE ia11='North Carolina'
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Aug 2008
    Posts
    31
    Perfect! Thank You!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles