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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:49:05+00:00 2026-06-10T15:49:05+00:00

The dilemma: I have options that need to store pricing data. Each option can

  • 0

The dilemma:

I have options that need to store pricing data.

Each option can have a different formula to determine it’s cost.

E.g., one option’s total cost will be cost * sq feet, but another option will be cost * perimeter feet, while another option still will simply be a fixed cost.

These options are being pulled from the database by several sites that my company owns.

Each one of those sites needs to be able to calculate the options pricing in the exact same way.

We currently have PHP code on each site that pulls data from the database, and then determines how to calculate it.

The problem with this method is that we will sometimes change how a price is calculated, and when that happens, we have to edit the pricing module repository and then update it to each server that hosts one of these sites.

I’m looking for a better solution.

I’m toying with the idea of storing a formula in the option record in the database, then each site would simply need to call the option, apply data to the formula stored there, and then run the formula.

Now, this can be done with eval(), but I don’t really want to do it that way.

Eval example to give you a clearer idea of what I’m trying to do:

$product->width = 3;
$product->length = 4;
$formula = $option->cost_formula; // $product->width * $product->length * $option->cost
eval($formula);

Does anyone else have any other solution?

  • 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-10T15:49:07+00:00Added an answer on June 10, 2026 at 3:49 pm

    Use functions.

    Pseudo-code:

    CREATE FUNCTION calculation1 (@cost decimal(6,2), @feet int)
    RETURNS decimal(7,2)
    AS
    BEGIN
        --Other formula calculations
        RETURN @cost * @feet
    END
    

    You would then call the function from your query: SELECT calculation1('1.50', 15)...

    This way you can update any changes to your function and queries using the function will produce the same result.

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

Sidebar

Related Questions

I have a little dilemma that maybe you can help me sort out. I've
I have a dilemma where to store secret tokens that I receive from twitter.
I have the following dilemma with two elements (menu items) that I need to
I have a dilemma that I've encountered before. What's the best in terms of
i have little dilemma, i often use data-bound controls such as Gridview in conjunction
I have a dilemma. Let's assume(for simplicity's sake) I have four tables, with different
Here's my dilemma: I have two types of routes which are semantically very different,
My dilemma - I have a universal app that holds a lot of images
A little web design dilemma: I have a form with a lot of options,
I have a dilemma on my hands. After much trial and error, I still

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.