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

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

问题描述

有没有办法将数组存储到 mysql 字段中?我正在创建一个评论评级系统,所以我想存储用户 ID 数组以防止多次投票.我将创建一个新表,其中包含评论 ID 和对该评论进行投票的用户 ID 数组.然后我将加入评论表和这个表并检查当前用户 ID 是否存在于选民数组或注释中.如果这样做,则投票图标将被禁用.我想我会阻止以这种方式在循环中使用 mysql 查询.

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?

推荐答案

您始终可以序列化数组并将其存储在数据库中.
PHP 序列化

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天全站免登陆