Note that there are some explanatory texts on larger screens.

plurals
  1. POBest way to structure pricing matrix in MySQL?
    primarykey
    data
    text
    <p>I am working on a site where a user can:</p> <ol> <li>Choose a product (window blinds)</li> <li>Choose a color (there are 3 groups of colors - A, B and C. The price depends on the color)</li> <li>Enter the size of the blind (in cm).</li> </ol> <p>When the user has entered the size and clicks enter, an ajax call will be fired to a PHP script that executes a query, looking into the database and finds the appropriate price.</p> <p>The sizes are in increments of 10cm. So like 100, 110, 120, 130 etc. So if the user writes 115, it would automatically choose 120 as the appropriate size/price (it will always round up).</p> <p>I have made this structure, but want to know if you have any ideas where I can optimize it to be faster/better.</p> <pre><code>products | id | SKU | name | category | 1 | 010101 | Window Blind 1 | Blinds | 2 | 020202 | Window Blind 2 | Blinds pricing_colors | id | group | color | 1 | A | Red | 2 | B | Green | 3 | C | Blue | 4 | D | White product_colors | id | sku | color_id | 1 | 010101 | 1 | 2 | 010101 | 2 | 2 | 020202 | 1 | 2 | 020202 | 3 pricing_matrix | id | sku | color_group | width | height | price | 1 | 010101 | A | 100 | 100 | 50 | 2 | 010101 | A | 110 | 100 | 55 | 3 | 010101 | A | 120 | 100 | 60 | 4 | 010101 | A | 100 | 110 | 53 | 5 | 010101 | A | 100 | 120 | 56 | 6 | 010101 | B | 100 | 100 | 60 | 7 | 010101 | B | 110 | 100 | 65 | 8 | 010101 | B | 120 | 100 | 70 | 9 | 010101 | B | 100 | 110 | 63 | 20 | 010101 | B | 100 | 120 | 66 </code></pre> <p>As you can see, the pricing_matrix table will be very large. As it will have all the widths and height for each of the 3 color groups in all width/height increments.</p> <p>Have thought about the following query to find the appropriate price:</p> <pre><code>SELECT price FROM pricing_matrix WHERE height &gt;= ... AND width &gt;= .... AND sku = .... AND color_group = 'A' ORDER BY height,width ASC </code></pre> <p>Please come with suggestions to how I can improve it! :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload