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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:13:37+00:00 2026-06-13T07:13:37+00:00

I need to find a better way to get the discount for each article

  • 0

I need to find a better way to get the discount for each article price in our web shop depending on which pricelist or pricelist/discount list a customer has. I think this is possible to do in just one query instead of the 5 I have today, but I really do not know where to start.

All our customers have a pricelist and some have both pricelist and one extra discount list. Today we have about 25 different pricelists and about 100 extra discount lists.
All the pricelists are structured in the same manner; they have a price group and a discount in percent.

For example pricelist 01 could look like

A 20

B 35

C 20

The extra discount list is structured in a different manner and can have a fixed price or percentage. It also has three different priority levels: discount based on the article code (has priority 1), based on category (has priority 2) and based on price group (has priority 3).

Discount list 0013 could look like:

In the article tab

PL-2344-444 40 (%)

P-0455-23 200 (SEK)

In the category tab

C12 50 (%)

N12 35 (%)

Today I have three different queries to see if I get a hit in the discount list:

First I check to see if I get a hit in priority 1: (FIXED returns f and PERCENTAGE r)

SELECT DISCOUNT, FIXED, PERCENTAGE FROM PUPRIREG 
WHERE ARTCODE = 'JO-23455' AND DISCOUNTLIST = '0013'

If the above returns 0, I do the second query, priority 2:

SELECT DISCOUNT, FIXED, PERCENTAGE FROM PUPRIREG 
WHERE CATEGORY = 'C15' AND DISCOUNTLIST = '0013'

And the last one priority 3:

SELECT DISCOUNT, FIXED, PERCENTAGE FROM PUPRIREG 
WHERE PRICEGROUP = 'F' AND DISCOUNTLIST = '0013'

If none of the extra discount lists returns 0 I get the discount from the pricelist

SELECT DISCOUNT FROM PUPRIREG WHERE PRICELIST = ’01’ AND PRICEGROUP = ‘F’

I call the function like follows
$discount = discount($articlecode, $category, $pricegroup);

function discount($articlecode, $category, $pricegroup){

$articlecode = sanitizingData($articlecode); 

$category = sanitizingData($category);

$pricegroup = sanitizingData($pricegroup);

// do priority 1

// prio 2

// prio 3

// pricelist

return $discount;

}

I would be so happy if someone could show me how to do this. I am using mysqli and php.

Many thanks

Best regards linda

  • 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-13T07:13:38+00:00Added an answer on June 13, 2026 at 7:13 am

    You can do the queries with a union:

    (SELECT DISCOUNT, FIXED, PERCENTAGE, 1 priority FROM PUPRIREG 
        WHERE ARTCODE = 'JO-23455' AND DISCOUNTLIST = '0013')
    union
    (SELECT DISCOUNT, FIXED, PERCENTAGE, 2 priority FROM PUPRIREG 
        WHERE CATEGORY = 'C15' AND DISCOUNTLIST = '0013')
    union
    (SELECT DISCOUNT, FIXED, PERCENTAGE, 3 priority FROM PUPRIREG 
        WHERE PRICEGROUP = 'F' AND DISCOUNTLIST = '0013')
    union
    (SELECT DISCOUNT, 0 fixed, 0 percentage, 4 priority FROM PUPRIREG
        WHERE PRICELIST = '01' AND PRICEGROUP = 'F')
    order by priority;
    

    The additional artificial priority column and order by ensures, that you get the discounts properly sorted.

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

Sidebar

Related Questions

I need to find a way to get actual page size in Google Chrome.
I need to findout a better and quick way to query MySQL table to
I need to find a right way to prevent two running instances of my
I am trying to find a better way to handle some growing if constructs
I need to find a better solution to pass the data type into boost::variant
Is there a workaround/better way to do this: I have a field (TEREMARKS) which
I need to get the content of folder deleted from our repository long time
I need a quick way to find out if a given port is open
Need to find the timestamp for the first minute of the first day of
I need to find a flexible solution for access control in PHP. In the

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.