【问题标题】:mySQL data type for form elements表单元素的 mySQL 数据类型
【发布时间】:2014-03-02 09:29:16
【问题描述】:

我在 pmySQL 中为复选框和单选按钮以及输入 type=date 使用什么数据类型??

<pre>
<tr>
   <td class="right_align">*Occupation : </td>
   <td>
      <input type="radio" name="occupation" value="student" />Student<br />
      <input type="radio" name="occupation" value="business" />Business<br />
      <input type="radio" name="occupation" value="pvtsect" />Priavte Sector<br />
      <input type="radio" name="occupation" value="govtsect" />Govt. Sector<br />
      <input type="radio" name="occupation" value="others" />Others<br />
   </td>
</tr>

<tr>
   <td class="right_align">*On which project you want to work :</td>
   <td>
      <input type="checkbox" name="" ="projectname" value="shine"/>Project Shine<br />
      <input type="checkbox" name="" ="projectname" value="sahyog" />Project Sahyog<br />
      <input type="checkbox" name="" ="projectname" value="smile" />Spreading Smiles                                                                              
   </td>
</tr>
</pre>

【问题讨论】:

  • 你在这里问之前用谷歌搜索过吗?
  • 您使用适合您存储的数据的任何内容,数据类型名称非常易于解释,varchar,text 用于文本,datetime 用于日期时间,int 用于整数等等.
  • 你可以使用,你想要什么。如果需要,您可以将复选框值保存在 BLOB 或 TEXT 中...

标签: php mysql input


【解决方案1】:

1) 你会得到字符串作为 radio 的值,所以它是 varchar 类型

2)对于复选框,任何一个都可以有多个值,因此您需要为此值创建一个单独的表(working_project)(数据类型将与radio相同)和另一个用于映射的表(user_working_project)

user_working_project 表将包含用户 ID 和工作项目 ID

例如,一个用户的 id=1,working_project=1,2

那么在您的 user_working_project 表中的条目将是这样的:

  user_working_project_id working_project_id user_id
  1                         1                    1
  2                         2                    1

【讨论】:

    猜你喜欢
    • 2018-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-18
    • 2020-04-24
    • 1970-01-01
    相关资源
    最近更新 更多