我正在研究一個菜單系統,它需要一個url然後查詢db來建立菜單。
我的菜單表:MySQL:結合多個條件
+---------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| node_id | int(11) | YES | | NULL | |
| parent | int(11) | YES | | NULL | |
| weight | int(11) | YES | | NULL | |
| title | varchar(250) | YES | | NULL | |
| alias | varchar(250) | YES | | NULL | |
| exclude | int(11) | YES | | NULL | |
+---------+--------------+------+-----+---------+----------------+
我的問題有關列別名,家長和NODE_ID。
因此,對於像網址:http://example.com/folder1/folder2/filename
別名將潛在=「文件名」,「文件夾1」,「文件夾2」
父=父文件夾的NODE_ID。
我所知道的是如何將網址拆分成數組並檢查每個部分匹配的別名。 我不知道的是如何獲得它,然後通過別名與「folder2」匹配並且其父別名與「folder1」匹配的父級進行過濾。 我想象的查詢,像這樣:
select * from menu
where alias='filename' and
where parent = node_id
where alias='folder2' and parent = node_id
where alias='folder1'
除非我知道上面是錯誤的。我希望這可以在一個查詢中完成。
感謝您提前提供任何幫助!
示例數據和預期產量會有所幫助。 – 2010-06-06 20:32:07