Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

mysql php decrement issue

  • 12-08-2004 09: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