Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To shorten things you could use a <em>single</em> flag-column (integer), indicating bit by bit which sizes are available for each article. The flag values are composed of these values which correspond to the available sizes:</p> <pre><code>flag size 2^ (bit no.) 1 XS 0 2 S 1 4 M 2 8 L 3 16 XL 4 </code></pre> <p>and so on. To have mutliples sizes available just enter the sum of the two size flags:</p> <pre><code>6 S,M </code></pre> <p>The individual sizes can be easily checked for by using a bitwise <code>AND</code> operator (<code>&amp;</code>) which is available in MySQL, PHP and JavaScript. A standard <code>int</code> column (4 bytes) already allows you to keep track of up to 32 different sizes and all their possible combinations.</p> <p>In an SQL statement, when you want to make sure a size M is available you simply use the WHERE clause</p> <pre><code>WHERE flag&amp;4 &gt; 0 </code></pre> <p>Or in a JavaScript section you can easily determine which checkboxes to activate by using something like <code>active = xl_flg &amp; flag &gt; 0</code> where <code>flag</code> is the variable containing the value from your MySQL column (possibly received through AJAX) and xl_flag is an attribute of your input field (or from the surrounding <code>&lt;div&gt;</code>). You can then act on the value of <code>active</code> (true or false) to <code>hide()</code> or <code>show()</code> the input element.</p> <p>If you want to set or unset the availability of an item in your back office simply do this (PHP):</p> <pre><code>// working with constants makes your life easier ... ;-) define("XS", 0); define("S", 1); define("M", 2); define("L", 4); define("XL", 8); // typically the following information is provided by an AJAX post // for example by adding the values of checked checkboxes ... $sizes= S + M + XL; // = 11 -- set (MySQL query string in PHP): $sql = "UPDATE ... SET flag = flag &amp; $sizes WHERE ... "; -- unset $sql = "UPDATE ... SET flag = flag &amp; ~$sizes WHERE ... "; </code></pre> <p><code>~</code> inverts all the bits in a number (acts like a logical <code>NOT</code>). The combination of <code>&amp;</code> and <code>~</code> switches off the bits set in the second operand.</p>
    singulars
    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.
 

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