Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7888047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:44:14+00:00 2026-06-03T05:44:14+00:00

Okay so this has been modified there is still 3 tables board, account, log

  • 0

Okay so this has been modified there is still 3 tables board, account, log

Thanks to Bryan Moyles he kind of give me an epiphany

here’s my code

$query=$S->query("
    SELECT
        `TBL`.`LAcc`,
        `TBL`.`AId`,
        `TBL`.`Add`,
        `TBL`.`Lost`,
        `TBL`.`LDate`,
        `TBL`.`FDate`

        FROM (
            SELECT 
                (SELECT SUM(`Add`) FROM `m_rules` GROUP BY `Group`) AS `Add`,
                `S`.`Account` as `LAcc`,
                `P`.`Id` as `AId`,
                SUM(`S`.`Loss`*`S`.`Multiple`) AS `Lost`,
                MAX(`S`.`Timestamp`) AS `LDate`,
                MIN(`S`.`Timestamp`) AS `FDate`
                    FROM `log` AS S,`account` AS P

            GROUP BY `P`.`Id`
        ) as `TBL`
        WHERE `TBL`.`FDate` <= NOW()
        AND `TBL`.`LDate` >= DATE_SUB(NOW(), INTERVAL 1 DAY)

") or die(mysql_error());

    while($Log=$S->fetch($query)) { 

        if($Log['AId']==$Log['LAcc']) {
            $Score=$Log['Add']-$Log['Lost'];
        } else {
            $Score='Bonus';
        }

        /*
            echoing to see results
        */
        echo $Log['AId'].' : '.$Score.'<br />';

        /* 
        This is what the query would look like Thanks to Bryan Moyles,

        $S->query("INSERT INTO `board` (`Account`,`Score`, `Date`)VALUES('".$Log['Id']."', '".$Score."', 'NOW()') ON DUPLICATE KEY UPDATE Score = '".$Score."'");
        */
    }

Here you go all results: Group by Account ID

Account Id:4, Log Account:5, Add: 97.64236, Lost:141.11371 LastDate:2012-05-04 22:07:46, FirstDate:2012-05-04 22:05:48, Score:Bonus
Account Id:5, Log Account:5, Add: 97.64236, Lost:141.11371 LastDate:2012-05-04 22:07:46, FirstDate:2012-05-04 22:05:48, Score:-43.47135
Account Id:6, Log Account:5, Add: 97.64236, Lost:141.11371 LastDate:2012-05-04 22:07:46, FirstDate:2012-05-04 22:05:48, Score:Bonus
Account Id:7, Log Account:5, Add: 97.64236, Lost:141.11371 LastDate:2012-05-04 22:07:46, FirstDate:2012-05-04 22:05:48, Score:Bonus
Account Id:8, Log Account:5, Add: 97.64236, Lost:141.11371 LastDate:2012-05-04 22:07:46, FirstDate:2012-05-04 22:05:48, Score:Bonus

GROUP BY Log Account ID

Account Id:4, Log Account:4, Add: 97.64236, Lost:119.67095 LastDate:2012-05-04 22:07:46, FirstDate:2012-05-04 22:06:29, Score:-22.02859
Account Id:4, Log Account:5, Add: 97.64236, Lost:542.30295 LastDate:2012-05-04 22:06:54, FirstDate:2012-05-04 22:05:48, Score:Bonus
Account Id:4, Log Account:6, Add: 97.64236, Lost:43.59465 LastDate:2012-05-04 22:07:06, FirstDate:2012-05-04 22:07:06, Score:Bonus

I see the problem just not sure of the solution..

SOLVED!

I replaced

FROM `log` AS S,`account` AS P

With

FROM `account` AS `P` LEFT JOIN `log` AS `S` ON `P`.`Id`=`S`.`Account`

in the original query (before I modified and changed it on here) I had the account and log in reverse along with the P.Id=S.Account which didn’t work so I just swapped log and account around and it works.. can’t believe that was the issue but thank you for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:44:15+00:00Added an answer on June 3, 2026 at 5:44 am

    I’m not sure how you would ever come across a situation where the log didn’t exist, being that you’re building your data off of the results of a query. However, you’re inserting the primary key, and you can catch the duplicate key error, and run an update accordingly.

    Check out this article
    http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html

    $S->query("INSERT INTO `board` (`Account`,`Score`, `Date`)VALUES('".$Log['Id']."', '".$Score."', 'NOW()') ON DUPLICATE KEY UPDATE Score = '".$Score."'");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I know this question has been asked before: Previous Question I have also
Okay, now I've been using drawImage in java for a while, and this has
Okay, two admissions here, one is I'm sure this question has been answered and
Okay this one has me stumped.. mainly because i have been working on this
Okay i know this has been a question asked b4, but since it should
Okay, I know this has been asked before, but the solutions to previously asked
Okay I'm really sorry if this question has been asked, but I can't seem
Okay people, I'm sure someone has had this issue and can help me out.
Okay this is my 4th question today on Scheme, still pretty new to Scheme,
Is it okay( and legal) to delete a pointer that has been passed as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.