如何将数组存储到mysql中? [英] How to store an array into mysql?

查看:235
本文介绍了如何将数组存储到mysql中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法存储数组到mysql字段?我创建一个评论评级系统,所以我想存储用户ID的数组,以防止多个投票。我将创建一个新表,其中包含评论ID和对此评论投票的用户ID数组。比我将加入注释表和此表,并检查当前用户id是否存在于数组或注释。如果它不是投票图标将被禁用。我想我会阻止以这种方式在循环中使用mysql查询。



你碰巧知道更好的方法吗?


手动/ en / function.serialize.phprel =noreferrer> PHP序列化



然后可以在需要时取消序列化数组。

Is there a way to store an array into mysql field? I'm creating a comment rating system so I want to store the arrays of user ids to prevent multiple votings. I'm going to create new table that holds the comment id and the array of user ids who have voted on this comment. Than I'll join comments table and this table and check whether the current user id exists in the voters array or note. If it does than the voting icons would be disabled. I think I'll prevent to use mysql query in loop in this way.

Do you happen to know any better ways?

解决方案

You can always serialize the array and store that in the database.
PHP Serialize

You can then unserialize the array when needed.

这篇关于如何将数组存储到mysql中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆