I am trying to create a dropdown box where it has from 10 - 90, I want each value to stand for the numbers in between (so 10 will hold 11, 12, 13, 14.. and so on and so forth).
I am assuming you are retrieving this integers from the PHP source code. In that case, just store this logic somewhere in your database
, php file
or some sort of a config file
in order to keep this logic server-sided. It is not possible to store multiple values in one option, that's the idea of an option. Or you would have to store it as a json_encode
string, but I am not sure if that is what you want.
It would safer as well to put this on your server-side, I am not sure what you are creating, but safety is always a pre.
More about json encoding
Simple answer: you cannot store multiple values in one option tag value.
The simplest and safest solution would be to store one value in the option value (e.g. 10
) and then treat this as a range from the value set to the next multiple of 10:
'AND col >= '.$value.' AND col < '.$value+10
A second solution would be to set the value to be a range like 10-19
and then on the server side:
list($min,$max) = explode('-',$value);
... 'AND col >= '.$min.' AND col <= '.$max ...
Another solution would be to store a JSON encoding of an array containing the values you wish to encapsulate in the one option and then decode the value on the server side:
'AND col IN ('.implode(',',json_decode($value)).')'
I personally would avoid the JSON approach as it is overkill for this kind of problem.
The value of an <option>
can be any string; it's up to your server-side code to interpret that string appropriately.
Rather than always using the string-match operator LIKE
in your SQL, you need to choose appropriate conditions for each of your columns.
For instance, set your value to be a range specified by min and max: <option value="11-20">foo</option>
and then use <=
and >=
in your SQL (beware of "fence-post errors"!)
list($min,$max) = explode('-', $_POST['trayheight']);
$sql .= 'And trayheight >= ' . intval($min) . ' And trayheight <= ' . intval($max);