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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:51:50+00:00 2026-06-03T12:51:50+00:00

Im sure the solution is fairly simple, my brain however doesn’t appear to be

  • 0

Im sure the solution is fairly simple, my brain however doesn’t appear to be in a right state of mind today. I have a MySQL table storing a pricing matrix of my products.

ID     PRODUCT     MINIMUM     PRICE
1      1           2           15
2      1           4           12
3      1           6           10

So a quick explanation, for the product with the id 1, if the customer has a minimum quantity of 2 in their shopping basket the price of each item is bought down to £15. If the user then puts another 2 products In their basket the price of each with be decreased to £12.

THE PROBLEM: I need a way of validating a new price tier each time one is added. So if someone wants to add a new tier of:

ID     PRODUCT     MINIMUM     PRICE
4      1           3           16

This shouldn’t be allowed as in this case the price of each item would increase if the user chooses to purchase three items rather than two. So I need to ensure that prices entered are decreasing as the quantity increases based on values already in the database.

$query = 'select id,minimum,price from `cat.tier_price` where product = %d order by minimum asc;';
$query = sprintf($query, (int)$identity);
if(!$return = $db->query($query)){
    echo 'MySQL error!';
}else{
    $quantity = $_POST['quantity'];
    $price = $_POST['quantity'];

    if($return->num_row){
        while($tier = $return->fetch_object){

        }
    }
}

If I haven’t made this clear enough please do say. Any help would be greatly appreciated.

  • 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-03T12:51:53+00:00Added an answer on June 3, 2026 at 12:51 pm

    This could be done by a simple function:

    function validateTier($productId, $minimum, $price) {
        // check if the new tier is not higher price for higher minimum
        $query = 'SELECT 1 AS exists FROM `cat.tier_price` WHERE `product` = {$productId} AND `minimum` < {$minimum} AND `price` > {$price} ORDER BY `minimum` DESC LIMIT 1';
        $res = mysql_query($query);
        $result = mysql_fetch_assoc($res);
    
        if(isset($result['exists']) && $result['exists']) {
            // check if the new tier is not lower price for lower minimum
            $query = 'SELECT 1 AS exists FROM `cat.tier_price` WHERE `product` = {$productId} AND `minimum` > {$minimum} AND `price` < {$price} ORDER BY `minimum` ASC LIMIT 1';
            $res2 = mysql_query($query);
            $result2 = mysql_fetch_assoc($res2);
    
            if(isset($result2['exists']) && $result2['exists']) return true;
        }
    
        return false;
    }
    

    You then call this function whenever a new tier should be added. The function tries to select exactly one record where minimum is lower than the one being inserted and the price is higher then the one being inserted. If this query succeeds it will return 1 (considered as true) and this means that the new tear might be inserted. Otherwise the FALSE will be returned which means that the new tier is incorrect.

    But I think this should also do a trick (and is more simple):

    function validateTier($productId, $minimum, $price) {
        // check if the new tier is not higher price for higher minimum
        $query = 'SELECT 1 AS exists FROM `cat.tier_price` WHERE `product` = {$productId} AND ((`minimum` < {$minimum} AND `price` > {$price}) OR (`minimum` > {$minimum} AND `price` < {$price})) LIMIT 1';
        $res = mysql_query($query);
        $result = mysql_fetch_assoc($res);
    
        if(isset($result['exists']) && $result['exists']) return true;
    
        return false;
    }
    

    Please, let me know if this also works.

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

Sidebar

Related Questions

Im sure there is a very simple solution for this. I have a bunch
I'm fairly sure there has to be a simple solution to my problem, but
I have a fairly simple table requestparams ( requestid varchar(64) NOT NULL, requestString text,
I have a fairly simple sync problem. I have a table with about 10
I'm fairly sure there should be an elegant solution to this (in MATLAB), but
Im pretty sure this has a simple solution. I am using jCarousellite, and i
I'm pretty sure there is a very simple solution here but I can't seem
I feel like there's a simple solution to this, but I'm not really sure
I'm sure this question is fairly simple to answer... is there any way to
I am learning LINQ and this seems like a fairly simple problem. I have

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.