1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Giving all Users Refund

Discussion in 'PHP' started by CuBz, Nov 26, 2007.

  1. #1
    I have a game website and I want to empty everyones garage (delete all their cars) but i want them to recieve the money back that the car is worth.

    How would i do it?

    Cars are in a table named 'garage' and the money is in the 'users' table

    Cheers ;)
     
    CuBz, Nov 26, 2007 IP
  2. selling vcc

    selling vcc Peon

    Messages:
    361
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Can you show us your DB structure and how do you calculate the amount to refund ?

    Thanks
     
    selling vcc, Nov 26, 2007 IP
  3. CuBz

    CuBz Peon

    Messages:
    117
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Table Name:

    garage

    Table garage contains:

    id, owner, car_name, worth

    I want the 'worth' to go to the 'owners' money

    so it would be 'update users set money =XXXXX'

    Cheers
     
    CuBz, Nov 27, 2007 IP
  4. Big 'G'

    Big 'G' Member

    Messages:
    89
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    48
    #4
    How many records are you talking approx.

    a simple solution if not many records something like
    
    $query ="SELECT * FROM garage";
    $result =mysql_query($query);
    
    while($row =mysql_fetch_assoc($result)){
        $query2 ="UPDATE users SET money=money + $row['worth'] WHERE user_id='".$row['owner']."'";
        
        if(mysql_query($query2)){
          $d_query ="DELETE * FROM garage WHERE id='".$row['id']."'";
         mysql_query($d_query);
        }
    
    
    
    }
    PHP:
    you need to format the sql a bit to suit.

    If you have an excessive amount another option would be to get all the distinct user from garge and sum the worth of the cars in one sql then update the users table
     
    Big 'G', Nov 27, 2007 IP
  5. imvain2

    imvain2 Peon

    Messages:
    218
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You could actually do this in two mySQL commands, without PHP loops.

    UPDATE users, garage SET users.money = users.money + garage.worth WHERE users.user_id = garage.owner

    then run:

    delete from garage

    I just tested this out to make sure it works.
    You will need to fix the tables and column fields for your needs.
     
    imvain2, Nov 27, 2007 IP
  6. CuBz

    CuBz Peon

    Messages:
    117
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Tried that and got

    Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/a/m/a/amafiali/html/clear_garage.php on line 9

    line 9 is this...

    $query2 ="UPDATE users SET money=money + $row['worth'] WHERE user_id='".$row['owner']."'";        
    
    PHP:
    O and i forgot to mention it is a LOT of records
     
    CuBz, Nov 28, 2007 IP
  7. imvain2

    imvain2 Peon

    Messages:
    218
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #7
    The code that I posted will work for any amount of records, large and small. Since the only php required is just to run the queries. However, this can be done through something like phpmyadmin.


    Here is a fix for BIG G's code

    
    $query2 ="UPDATE users SET money=money + '".$row['worth']."' WHERE user_id='".$row['owner']."'";
    
    PHP:
     
    imvain2, Nov 28, 2007 IP
  8. CuBz

    CuBz Peon

    Messages:
    117
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Works but loading takes too long and it isnt my server

    SOmebody elses script works but just didnt refund them, it just deleted the cars

    Here is what i have


    <?php
    include_once"includes/db_connect.php";
    include_once"includes/functions.php";
    
    if (strip_tags($_POST['submit'])){
    $query ="SELECT * FROM garage";
    $result =mysql_query($query);
    while($row =mysql_fetch_assoc($result)){    
    $query2 ="UPDATE users SET money=money + '".$row['worth']."' WHERE username='".$row['owner']."'";
    if(mysql_query($query2)){
    $d_query ="DELETE * FROM garage WHERE id='".$row['id']."'";
    mysql_query($d_query);    
    }
    mysql_query("INSERT INTO `topics` (`id`, `username`, `title`, `topictext`, `forum`, `locked`, `sticky`, `lastreply`,`made`,`crew`) 
    VALUES ('', 'CuBz', 'Garages Cleared', 'All garages have been cleared and you have recieved your money for each car', 'main', '0', '1', '999999999999','$date','$fetch->crew');") or die (mysql_error());
    echo"All Users Refunded";
    }
    }
    
    ?>
    PHP:
    <center><br><Br>
    
    <form method="post" name="form8" action="">
    
    <table height=100 width="600" border="0" align="center" cellpadding="2" cellspacing="0" bgcolor="#000000"><tr><td align=center background=includes/grad.jpg height=30>
    Empty Garages</td></tr><tr>
    
    
    <td align=center>Clear Garages and give everyone their money for the cars</td></tr>
    <td align=center><input type="submit" value="submit" name="submit" class="custombutton"></td></tr>
    
    </form></table>
    HTML:
     
    CuBz, Nov 29, 2007 IP