這裏是我的表結構:如何爲自動填充框選擇標籤?
// tags
+----+------------+----------------------------------+----------+----------+------------+
| id | name | description | related | used_num | date_time |
+----+------------+----------------------------------+----------+----------+------------+
| 1 | PHP | some explanations for PHP | 1 | 4234 | 1475028896 |
| 2 | SQL | some explanations for SQL | 2 | 734 | 1475048601 |
| 3 | jQuery | some explanations for jQuery | 3 | 434 | 1475068321 |
| 4 | MySQL | some explanations for MySQL | 2 | 657 | 1475068332 |
| 5 | JavaScript | some explanations for JavaScript | 3 | 3325 | 1475071430 |
| 6 | HTML | some explanations for HTML | 6 | 2133 | 1475077842 |
| 7 | postgresql | some explanations for postgresql | 2 | 43 | 1475077851 |
| 8 | script | some explanations for script | 8 | 3 | 1475077935 |
+----+------------+----------------------------------+----------+----------+------------+
現在我需要他們的名字的一部分選擇標籤的基礎上,我也需要選擇所有相關的標籤。
對於實施例:
字符串:scr
。預期產出:
+----+------------+----------------------------------+----------+----------+------------+
| 3 | jQuery | some explanations for jQuery | 3 | 434 | 1475068321 |
| 5 | JavaScript | some explanations for JavaScript | 3 | 3325 | 1475071430 |
| 8 | script | some explanations for script | 8 | 3 | 1475077935 |
+----+------------+----------------------------------+----------+----------+------------+
-- Noted that "jQuery" tag is selected because of its relation with "JavaScript" tag
字符串:ph
。預期產出:
+----+------------+----------------------------------+----------+----------+------------+
| 1 | PHP | some explanations for PHP | 1 | 4234 | 1475028896 |
+----+------------+----------------------------------+----------+----------+------------+
字符串:ys
。預期輸出:
+----+------------+----------------------------------+----------+----------+------------+
| 2 | SQL | some explanations for SQL | 2 | 734 | 1475048601 |
| 4 | MySQL | some explanations for MySQL | 2 | 657 | 1475068332 |
| 7 | postgresql | some explanations for postgresql | 2 | 43 | 1475077851 |
+----+------------+----------------------------------+----------+----------+------------+
-- Noted that both "SQL" and "postgresql" are selected because of their relation with "MySQL" tag
我怎麼能這樣做?
其實我是這樣做的:
SELECT * FROM tags WHERE name LIKE %:str%
但我查詢不支持related
列。
@Drew是啊我知道,這不是你推薦的數據庫設計。 –