Having multiple values within an

前端 未结 3 489
Happy的楠姐
Happy的楠姐 2021-01-24 10:51

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).

3条回答
  •  广开言路
    2021-01-24 11:27

    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.

提交回复
热议问题