简体   繁体   English

sql表结构存储html选择数据

[英]sql table structure to store an html select data

I want to store a html select data in a table , like an option's value , it's text and some optgroup in between, so that i can recreate select with least processing 我想在表中存储一个html select数据,例如一个option的value,它是文本,中间还有一些optgroup, 这样我可以用最少的处理来重新创建select

currently i have a setup of a two column table ( value<int>,text<varchar> ), i can't figure out how can i insert a blank optgroup? 目前,我有两列表的设置( value<int>,text<varchar> ),我不知道如何插入空白的optgroup?

the html select is like this - HTML选择是这样的-

<select name="height" id="height" class="sel_lng" required>
        <option value="">Please select</option>
        <option value="1">v1</option>
        <option value="2">v2</option>
        <option value="3">v3</option>
        <option value="4">v4</option>
        <optgroup label="&nbsp;"></optgroup>
        <option value="5">v5</option>
        <option value="6">v6</option>
</select>

the table would look like 桌子看起来像

value   text
1       v1
2       v2
3       v3
4       v4 <-- i would like to add an optgroup after this row
5       v5
6       v6

If values need to be sorted by number, you can just add float value 4.5, text NULL. 如果需要按数字对值进行排序,则只需添加浮点值4.5(文本为NULL)即可。 On the front end replace all floating point numbers with optgroup . 在前端,将所有浮点数替换为optgroup

Option groups should contain the options they're grouping: 选项组应包含它们正在分组的选项:

<optgroup>  
    <option>1<option>  
    <option>2<option>  
<optgroup>  

So, I would think you can add a new table with value <int> , value <int > where column 1 is an arbitrary option group id and column 2 is the option id. 因此,我认为您可以添加一个具有值<int> ,值<int >的新表,其中第1列是任意选项组ID,第2列是选项ID。 If you would have items that don't belong to a group, simply don't add them to the option group table. 如果您有不属于某个组的项目,只需不将其添加到选项组表中即可。

The new table would look like: 新表如下所示:
opt_group_id, opt_id opt_group_id,opt_id
1, 5 1、5
1, 6 1、6

HTH 高温超导

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM