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 2 of 2

Thread: PHP help

  1. #1
    New Coder
    Join Date
    Jul 2009
    Posts
    68
    Thanks
    1
    Thanked 1 Time in 1 Post

    PHP help

    Hey, I'm looking for a bit of help on the project I'm working on.

    This is my database structure 'users':


    PHP Code:
    <?php
        $offerUid 
    mysql_real_escape_string($_GET['coid']);
        
        
    $result mysql_query("SELECT * FROM pending WHERE id='$offerUid'");
        
    $data mysql_fetch_array($result);
        
    $value $data['amount'];
        
    $offer $data['offerID'];
        
    $userid $data['userID'];
        
    $user2 $data['username'];

    $bresult mysql_query("SELECT * FROM users WHERE id='$userid'");
        
    $getui mysql_fetch_array($bresult);
        
    $balance $getui['complete'];
        
    $pending $getui['pending'];
        
    $newbalance $balance $value;
        
    $newpending $pending $value;
        
        
    mysql_query("UPDATE users SET complete='$newbalance' WHERE id='$userid'");
        
    mysql_query("UPDATE pending SET status='1' WHERE id='$offerUid'");
        
    mysql_query("UPDATE users SET pending='$newpending' WHERE id='$userid'");
        echo 
    "The offer has been confirmed and the user has been credited.";
        
    ?>
    The code above takes the value of an item in 'pending' and puts it the `complete` field in users.

    I would like it so that when `complete` goes over 1.00 it will then get the id of the user it was referred by from `refer` and put a 1 in their `completereferrals`.

    eg. User1 refers User2. User1's id is then placed in User2's refer field. User2's complete field goes over 1.00. 1 is then added to User1's complete refer field.

    Can anyone help me out with this please?

    Thanks.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Thats simply a matter of determining the $newbalance value and going from there:
    PHP Code:
    $bresult mysql_query("SELECT * FROM users WHERE id='$userid'"); 
        
    $getui mysql_fetch_array($bresult); 
        
    $balance $getui['complete']; 
        
    $pending $getui['pending']; 
        
    $newbalance $balance $value
        
    $newpending $pending $value
         
        if (
    $newbalance 1.0)
        {
            
    mysql_query("UPDATE users SET completereferrals = completereferrals + 1 WHERE id = '" $getui['refer'] . "'");
        }

        
    mysql_query("UPDATE users SET complete='$newbalance' WHERE id='$userid'"); 
        
    mysql_query("UPDATE pending SET status='1' WHERE id='$offerUid'"); 
        
    mysql_query("UPDATE users SET pending='$newpending' WHERE id='$userid'"); 
        echo 
    "The offer has been confirmed and the user has been credited."
    I have no idea what you're datatypes are though, so I assumed they were strings to match you're other queries. Also, combine the first and third updates into a single query since they both use the same table and criteria.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

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