它应该是这样的
db_url db_tags
id url id url_id 标签
|----------------------|
class UrlTags
{
public $url_id;
public $url;
public $tags = array();
}
因此,当您需要保存带有相应标签的 URL 列表时。
$url_tags = new UrlTags();
$url_tags->$id = 1;
$url_tags->$url = 'http://www.example.com';
$url_tags->$tags[0] = 'zero';
$url_tags->$tags[1] = 'one';
$url_tags->$tags[2] = 'two';
或者更多面向对象的风格:
class Url
{
public $url_id;
public $url;
public $tags = array();
}
class Tags
{
public $tag_id;
public $tag_name;
}
$url_list = new Url();
$url_list->$id = 1;
$url_list->$url = 'http://www.example.com';
$tag = new Tags();
$tag->$tag_id = 1;
$tag->$tag_name = 'one';
//Now store the tags
$url_list->$tags[0] = $tag;
$tag = new Tags();
$tag->$tag_id = 2;
$tag->$tag_name = 'two';
$url_list->$tags[1] = $tag;