應該是這樣的
db_url db_tags
id url id url_id tag
|---------------------|
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;
每個url都有幾個標籤,這是否意味着,tag =>也會是一個數組?我需要在mysql查詢後以dinamically填充 – 2013-02-15 04:12:14
我認爲響應$ list是所有「tag」記錄的數組,並且引用了它所屬的URL。我假設會有第二個數組,$ URL_List = array(1 =>「http:// someUrl」,2 =>「http:// someOtherUrl」)... – AndrewP 2013-02-15 04:40:29