MYSQL - Store an array of URL's in a table
I need to store data in a Mysql table to allow me to export json data as follows:
[
{
"xxxx_identifier" : "XX_xxxxs_xxxx",
"xxxx_title" : "Xxxxx Xxxxx",
"xxxx_thumb" :开发者_运维技巧 "xxx_xxxxs_xxxx",
"xxxx_download_url" : "http://xxxx",
"xxxx_price" : x.xx,
"xxxx_badgemessage" : "xxx",
"xxxx_previews" : [
"http://xxx/xxx.zip",
"http://xxx/xxx.zip",
"http://xxx/xxx.zip"
]
}
]
I'm using 'json_encode($arr);' to create a json data.
How would I go about storing urls for the above field: "xxxx_previews" I want to be able to add as many as I like.
I can't seem to find any pointers, except that joining two tables may be the answer - but don't know how to do so.
Much appreciated.
In a relational, normalized database model, joining tables is the way to go:
table RESOURCE
xxxx_identifier /* primary key */
xxxx_title
...
table URL
xxxx_identifier /* foreign key to RESOURCE */
url /* the URL */
Add a column which contains the action items corresponding to its url to the The table in which u will b adding the url's.
create table { identifier , urls }
You can create 2 tables with a structor similar to the following :
table one would be like what you have except that
xxxx_previews
would be a foreign key for the second table.this table would have a 3 fields, one would be, ID ( primary key thats unique for every entry) previewID (this will allow you to link the entries in the first DB to this one) and URL (this will include the URL you want to add).
you can simply write a php script, read the xxxx_previews and then search the second table for previewIDs that match xxxx_previews.
精彩评论