我正在研究一个菜单系统,它需要一个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