Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

mysql php decrement issue

  • 12-08-2004 8:02am
    #1
    Registered Users, Registered Users 2 Posts: 648 ✭✭✭


    Hi, ive an issue decrementing a value i grab from a my sql table... can anyone see any thing wrong with this...




    firrst i get the counter value (to be decremented)

    $counter=0;
    $query = "SELECT counter FROM guest_admin WHERE username = '" .$table. "'";
    $req = mysql_query($query) or die (mysql_error()); 
    if ($req > 0) {
    $r = mysql_fetch_array($req);
    $counter = $r['counter']s;
    }
    



    then inside a loop i decrement it
    $counter = $counter--;
    


    then after the loop i update the table:
    $queryud = "UPDATE guest_admin SET counter='".$counter."' WHERE username = '" .$table. "'";
    mysql_query($queryud) or die (mysql_error()); 
    mysql_close();
    


    Tnx


Comments

  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    $counter = $counter--;
    

    I think you are going against the whole idea of the --. Basically thats there so as it is convienent for you not to have to go $var =, but instead say $var--

    Your code should be just
    $counter--;
    

    Also
    $counter = $r['counter']s;
    

    I maybe not advanced and not understand this, but whats with the s?

    Hope this helps someway


  • Registered Users, Registered Users 2 Posts: 648 ✭✭✭ChicoMendez


    what was i thinking of
    $counter--;
    
    did the job!!

    cheers

    the s business was i typo---

    Tnx


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    No probs :)


  • Registered Users, Registered Users 2 Posts: 648 ✭✭✭ChicoMendez


    1 other question for you.

    is there any way i could decrement that counter in the mysql table without using php . ie just SQL .....

    TNX


Advertisement