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.
Page 2 of 2 FirstFirst 12
Results 16 to 30 of 30
  1. #16
    Regular Coder
    Join Date
    Aug 2006
    Location
    Richmond, CA
    Posts
    204
    Thanks
    3
    Thanked 11 Times in 10 Posts
    It's not impossible. It's totally possible. You're doing it. What you are failing to understand is that the query you are sending to the database will only return rows where the receive date is today's date. So the "if" is redundant, the receive date will always be today's date.

    It's like:

    PHP Code:
    $x 100;
    if (
    $x == 100) {    // <==  Why would you do this?  You *KNOW* $x will be 100!
        // do something....


  2. #17
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    So you are saying that in the query to remove the "receivedate=CURRENT_DATE" and leave only "longterm!=0". That way every account that is using longterm savings will come up, then I can do a PHP check to find if the date matches or not?
    Been a sign maker for 7 years. My business:
    American Made Signs

  3. #18
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,338
    Thanks
    13
    Thanked 348 Times in 344 Posts
    do it the other way round. leave "receivedate=CURRENT_DATE" in the SQL and remove the PHP check.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  4. #19
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    I tried that last time and only one side of it works. It'll successfully find out who's 30 days is finished and deposit the gold, but no way to find out if it doesn't match and keep adding interest to the other accounts.
    Been a sign maker for 7 years. My business:
    American Made Signs

  5. #20
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,338
    Thanks
    13
    Thanked 348 Times in 344 Posts
    Quote Originally Posted by myfayt View Post
    but no way to find out if it doesn't match and keep adding interest to the other accounts.
    you would need another script for that. just make a new query that matches those accounts which should get added interest

    something simple as
    Code:
    UPDATE 
        rod_bank 
    SET 
        money = money + 1 -- or whatever you do to add interest
    WHERE
            longterm    <> 0
        AND receivedate  > CURRENT_DATE
    ;
    Last edited by Dormilich; 07-17-2014 at 09:37 AM. Reason: beautifying
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  6. #21
    Regular Coder
    Join Date
    Aug 2006
    Location
    Richmond, CA
    Posts
    204
    Thanks
    3
    Thanked 11 Times in 10 Posts
    Quote Originally Posted by myfayt View Post
    So you are saying that in the query to remove the "receivedate=CURRENT_DATE" and leave only "longterm!=0". That way every account that is using longterm savings will come up, then I can do a PHP check to find if the date matches or not?
    You could do it that way, or you could just write database query like this:
    Code:
    UPDATE rod_bank SET interest=interest+(longterm*.02) WHERE longterm<>0 AND receivedate=CURRENT_DATE
    instead of having to go through each row in PHP.

    EDIT: Of course after I post, I notice Dormilich says same thing.

  7. #22
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,338
    Thanks
    13
    Thanked 348 Times in 344 Posts
    Quote Originally Posted by Daniel Israel View Post
    EDIT: Of course after I post, I notice Dormilich says same thing.
    because it’s the obvious thing to do.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  8. #23
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    Makes sense! I shall try
    Been a sign maker for 7 years. My business:
    American Made Signs

  9. #24
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    So this should be what you mean?

    PHP Code:
    $bquery mysqli_query($link"SELECT * FROM rod_bank WHERE longterm!=0");
    $brow mysqli_fetch_array($bquery);

    $amount $brow['longterm'];
    $interest $amount .02;

    mysqli_query($link"UPDATE rod_bank SET interest=interest+$interest WHERE longterm!=0 AND receivedate!=CURRENT_DATE");
    mysqli_query($link"UPDATE rod_bank SET bank=bank+".$brow['interest'].", longterm=0, longtermdate='0000-00-00', receivedate='0000-00-00', interest=0 WHERE longterm!=0 AND receivedate=CURRENT_DATE"); 
    Been a sign maker for 7 years. My business:
    American Made Signs

  10. #25
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,338
    Thanks
    13
    Thanked 348 Times in 344 Posts
    yes (the principal logic is right) and no (there’s a fundamental flaw (you only calculate with the result of the first entry)).

    if I read the logic right you can do all the calculation in SQL.
    Code:
    -- it may take up more lines, but it’s way better readable this way
    UPDATE 
        rod_bank 
    SET 
        interest = interest + longterm/50 
    WHERE 
            longterm <> 0 
        -- it doesn't make sense to add interest if the receivedate is already past
        AND receivedate < CURRENT_DATE
    Code:
    UPDATE 
        rod_bank 
    SET 
        bank         = bank + interest, 
        longterm     = 0, 
        longtermdate = NULL, 
        receivedate  = NULL, 
        interest     = 0 
    WHERE 
            longterm <> 0 
        AND receivedate = CURRENT_DATE
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  11. #26
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    I am not familiar with that style of sql, can you explain what longterm/50 and the <> part is? So that I can learn from it. Thanks
    Been a sign maker for 7 years. My business:
    American Made Signs

  12. #27
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,338
    Thanks
    13
    Thanked 348 Times in 344 Posts
    erm ... x / 50 = x * 0.02 and <> is the standard SQL 'not equal' operator
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  13. Users who have thanked Dormilich for this post:

    myfayt (07-19-2014)

  14. #28
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    Seems to work perfectly! Thank you for the help. Will this update all accounts rather than just one? Thanks

    PHP Code:
    $bquery mysqli_query($link"SELECT * FROM rod_bank WHERE longterm!=0");
    $brow mysqli_fetch_array($bquery);

    $amount $brow['longterm'];
    $interest $amount .02;

    mysqli_query($link"UPDATE rod_bank SET interest=interest+$interest WHERE longterm!=0 AND receivedate<>CURRENT_DATE");
    mysqli_query($link"UPDATE rod_bank SET bank=bank+".$brow['interest'].", longterm=0, longtermdate='0000-00-00', receivedate='0000-00-00', interest=0 WHERE longterm!=0 AND receivedate=CURRENT_DATE"); 
    Been a sign maker for 7 years. My business:
    American Made Signs

  15. #29
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,338
    Thanks
    13
    Thanked 348 Times in 344 Posts
    your shown code will update all accounts with the interest of the first (or last, if used inside a loop) account. that’s why I said you should just use the two SQL statements. you don’t need PHP to calculate some intermediary values in this case.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  16. #30
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    Thanks
    Been a sign maker for 7 years. My business:
    American Made Signs


 
Page 2 of 2 FirstFirst 12

Posting Permissions

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