php如何一次性处理多个从表单处理的值,并且之间用“||”做分隔符?

WBOY
Release: 2016-06-06 20:48:19
Original
834 people have browsed it

php如何一次性处理多个从表单处理的值,并且之间用“||”做分隔符?例如兴趣爱好添加篮球,足球,等等作为一个字段存储到数据库当中,足球和篮球之间用||作为分隔符?

回复内容:

php如何一次性处理多个从表单处理的值,并且之间用“||”做分隔符?例如兴趣爱好添加篮球,足球,等等作为一个字段存储到数据库当中,足球和篮球之间用||作为分隔符?

不是挺懂你的问题的,如果你是想在爱好字段中存储多项数据的话,建议先将所有的爱好存储成数组形式,存入MySQL中的时候使用serialize()进行序列化,读取的时候使用unserialize()进行反序列化就可以了。

序列化是把数组或对象转变为字符串的一个过程,这样就能存储到数据库中了。

//Example
$hobby = array('篮球', '足球', '羽毛球', '计算机');

echo serialize($hobby);
//a:4:{i:0;s:6:"篮球";i:1;s:6:"足球";i:2;s:9:"羽毛球";i:3;s:9:"计算机";}
Copy after login

关于如何使用serialize()系列函数的话可以参考手册:

  • serilize()

  • unserilize()

我大概能理解你的意思吧,最初不懂数据库的我也是这么想的,如何在同一个字段存储多个值,其实你只需新建一个数据表即可,比如db_hobby,字段为“hobby user_id”即可

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!