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 8433519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:24:29+00:00 2026-06-10T06:24:29+00:00

This method is to select number of actions between User and TargetUser, e.g. just

  • 0

This method is to select number of actions between User and TargetUser, e.g. just between two users. The result values of this method are dependent of GetTotalOfPossibleActions() return value which is dynamic (every user has its own number).

Question: Is it better to move values computation to PHP layer out of SQL?

public function GetAction() {

    // ...

    $MaxActionCount = $this->GetTotalOfPossibleActions();

    return registry::getInstance()->get('DB')->select(
        'SELECT
            `Action`
            , `HA`.`Id` AS `ActionId`
            , IF(`Count` IS NULL
                , IF('.$MaxActionCount.' % 2
                    , IF(`HA`.`Id` = 1
                        , CEIL('.$MaxActionCount.' / 2)
                        , FLOOR('.$MaxActionCount.' / 2))
                    , '.$MaxActionCount.' / 2)
                , GREATEST(IF('.$MaxActionCount.' % 2
                    , IF(`HA`.`Id` = 1
                        , CEIL('.$MaxActionCount.' / 2) -  CONVERT(`H`.`Count`, SIGNED)
                        , FLOOR('.$MaxActionCount.' / 2) - CONVERT(`H`.`Count`, SIGNED))
                    , '.$MaxActionCount.' / 2 - `H`.`Count`), 0)
            ) AS `CountLeft`
        FROM `Help` AS `H`
        RIGHT JOIN `HelpAction`  AS `HA`
        ON `H`.`ActionId` = `HA`.`Id`
        AND `UserId` = '.$this->UserId.'
        AND `TargetUserId` = '.$this->TargetUserId.'
        AND `CreatedDate` = CURDATE()'));

}
  • 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-10T06:24:31+00:00Added an answer on June 10, 2026 at 6:24 am

    There is no hard and fast answer, but the following is a general guide I apply.

    PHP servers can be load balanced and multiplied. So if you’re running short on CPU cycles, you can add another PHP server relatively easily. Conversely, MySQL server can’t be easily multiplied. You can add replication servers and run complex “selects” on the slave servers, but replication adds a little stress and there is always a delay between an update on the master, and it being available on the slave. (Never believe the DB admin that says it’s milliseconds; and it gets slower when the server is under stress / with backups etc.)

    So +1 to PHP.

    However, SQL is built and designed to do computations with the data. That’s it’s job. It’s much more efficient at it (assuming you design the tables, queries and indexes correctly).

    So +1 to mySQL.

    If you do the computation on MySQL, you also don’t need to transfer the entire data table to PHP to process and handle. This saves netwerk traffic between the two.

    So +1 to mySQL.

    But if you’re struggling to get the queries right, or MySQL is using up all your memory, non-stop creating temporary tables and swapping to hard disk, it’s a lot easier to debug and find the problem by breaking down the computation in PHP. MySQL EXPLAIN and slow query logs are frustrating to decypher sometimes.

    So +1 to PHP.

    So… 2 all. If you have both on one server, and the queries are not giving you problems, let MySQL do it’s job. If you are having problems with queries, pull back into PHP. If you’re on multiple servers, do as much in MySQL as you can without reaching a bottleneck. If MySQL is a bottleneck and replication not possible, pull back into PHP. But then check network traffic.

    Then remember to re-evaluate when your load increases…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My current method is this: SELECT TOP 1 ID FROM DATAENTRY ORDER BY ID
I was using the Add class method $(select[name=' + ABC+ i + ']).addClass('addBorder'); This
hopefully a pretty simple question this time. I have a Select method in a
Is there any method to do this: SELECT * FROM `cores` WHERE superkinds IN
I have this controller method: public JsonResult List(int number) { var list = new
I'm trying to find the jQuery equivalent of this JavaScript method call: document.addEventListener('click', select_element,
This method right below reverses a doubly linked list with n elements. I dont
This method works as expected - it creates a JTree with a root node
This method that draws my tiles seems to be quite slow, Im not sure
This method is working totally right in matlab. but, when I compiled it in

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.