开发者

MYSQL - Store an array of URL's in a table

开发者 https://www.devze.com 2023-04-12 12:06 出处:网络
I need to store data in a Mysql table to allow me to export json data as follows: [ { \"xxxx_identifier\" : \"XX_xxxxs_xxxx\",

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 :

  1. table one would be like what you have except that xxxx_previews would be a foreign key for the second table.

  2. 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.

0

精彩评论

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