开发者

How can I store more than one value in a SQL table's column?

开发者 https://www.devze.com 2022-12-09 14:06 出处:网络
I am using PHP.I need to store the multiple values at a single column.The values are come from depending on the checkbox se开发者_开发知识库lected. I didnt use the array for checkbox name.What can I d

I am using PHP. I need to store the multiple values at a single column. The values are come from depending on the checkbox se开发者_开发知识库lected. I didnt use the array for checkbox name. What can I do?


You just need to find a standard way to store the information as a longer string.

So, for example, if you know '__' isn't going to show up in your data then you can store checkboxvalue__otherdata, but has risk.

As alex mentioned, if you use json, http://json.org, then you will put information into this object and then save it as a string, but to be safe you should base64 encode it.

Or you could store it in an xml file.

If you were just saving 2 bytes, for example, then you could push them into an int, and then decode it later.

Basically, just determine some way that works for you to store the type of data you want to store.

If you have a signed into that is always less than 2G and greater than 0 then you could put the checkbox (0 or 1) into the first bit of an unsigned int.

You didn't specify what the data you want to store is, so it is hard to give more detail.


If you had them in an array or object, you could serialise() before inserting into the db.

Alternatively, if you want something more readable, you could do json_encode() (but takes up more room).

0

精彩评论

暂无评论...
验证码 换一张
取 消