douping5015 2013-12-05 05:55
浏览 20
已采纳

如何使db表字段动态化

i am creating plugin in wordpress for contact us form and in that i am creating fields(textbox,textarea etc...) dynamically based on my requirement. so there is no fixed number of fields. i am storing dynamically created fields in my db table.

in some project i may require to create 3 fields and some project i may require to create 5 fields.. my dynamic form is working fine...

now my problem is DB. how do i create table to store contact us data? bcz sometimes there might be 3 fields and sometime there might be more than or less than 3 fields..

so my question is how do i make my table schema for this scenario...

suggestion will be highly appreciated...

Thanks in advnce

  • 写回答

5条回答 默认 最新

  • dongwo2772 2013-12-05 11:28
    关注

    i don't think so it's a good idea to do like this... but i am suggesting you this because in your case it might be useful

    you can do it by ALTER...

    so what you can do is "When you are creating new field dynamically at that time only you can create new column in your table like this...

       ALTER TABLE table_name ADD $name(Column name)  //$name may be your attribute name <input name="">
    

    and same way when you are deleting your field at that time you can drop your table column

       ALTER TABLE table_name DROP $name(Column name) //$name may be your attribute name 
    

    here i assumed that you have already created table table_name (without any fields)

    hope it may help you

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大