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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Mar 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP/MySQL problem..anyone?

    If i wanted to increment a database column's values (all of them) by one, every time a script ran...why won't this work?

    //<?
    // mysql_pconnect("host", "user", "password");
    // mysql_select_db("database");
    //
    // $result = mysql_query('select column from database');
    // @ $num_results = mysql_num_rows($result);
    //
    // mysql_query("update database set column = '$result'+1");
    //
    //?>



    Can anyone help please, I'm stuck..tried everything I can think of but still no go

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    there's a database called database and a table called database?

    other than that, just amend the update call

    mysql_query("UPDATE database SET column=" .($result+1));

    and if in future you get bad queries, just sling
    echo mysql_error();
    after the calls to point you in the right direction.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #3
    New to the CF scene
    Join Date
    Mar 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oops, yeah, the table should have been "table", i was just illustrating lol, rushed through it


    and still not working..no matter what value i start with in the columns, it sets them all to 3..? what the? lol...

    (for the record - it's not spitting out an error, just not incrementing the numbers in that column by one like it should)
    Last edited by davegarrad; 04-04-2003 at 10:01 AM.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it might be that $result is always returning as 2 and 2+1 = 3.

    perhaps just use an update without a prior select

    "UPDATE table SET column=column+1";
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #5
    New to the CF scene
    Join Date
    Mar 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK nevermind guys..I got it sorted

    //<?
    //mysql_pconnect("host", "user", "password");
    //mysql_select_db("database");
    //
    //$query = "select * from table";
    //$result = mysql_query($query);
    //$num = mysql_numrows($result);
    //$variablearray = mysql_fetch_array($result);
    //$currentvalue = $variablearray["column"];

    //mysql_query("UPDATE table SET column=" .($currentvalue+1));
    //?>


    sooooo simple, i don't know what i was doing with that first one lol And yes i'm going to clean all the junk out of that too


  •  

    Posting Permissions

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