2014-10-10 09:06
浏览 62


My current project consist of a Mysql table having 22 fields already.

I want to add a new field namely Permanent address. in the front-end its a textarea in which user will fill the following data's with either newlines or comma separated As per the standard of here, First string will House name, then Post office, then Place, then Pincode.

So I want to store it in a single coloumn namely "permanent_address". so how I store this comma/newline separated values into table field.?

Can it achieved by converting the comma/newline values into symbol ( @,#,%,&,* ) separated values, so that it can be stored to DB without violating 1st NF

enter image description here

图片转代码服务由CSDN问答提供 功能建议


我想添加一个新字段,即永久地址。 在前端它是一个textarea,用户将使用换行符或逗号分隔填写以下数据按照此处的标准,第一个字符串将是House名称,然后是Post Office,然后是Place,然后是Pincode。

所以我想把它存储在一个coloumn中,即“permanent_address”。 所以我如何将这个逗号/换行分隔值存储到表字段中。?

可以通过将逗号/换行值转换为符号(@,#,%,& ,*)分隔值,以便它可以存储到DB 而不会违反第一个NF

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtpfia3334 2014-10-10 09:20

    You can use explode function to split the text into different parts. It will work like this,

    $parts = explode(",",$input);  // this will split input in array, $input will have the text input
    $street_name = $parts[0];      // gives the first part 

    If you want to split by both "," and new line " ", you can use,

    $parts = preg_split( "/[,|
    ]/", $input );
    点赞 打赏 评论

相关推荐 更多相似问题