Home  >  Article  >  Backend Development  >  如果知道id为2了,如何一次搜索得出 “新闻 新闻上级”呢?

如果知道id为2了,如何一次搜索得出 “新闻 新闻上级”呢?

WBOY
WBOYOriginal
2016-06-13 10:37:49802browse

如果知道id为2了,怎么一次搜索得出 “新闻 新闻下级”呢??
表:table
id tid typename
1 0 根目录
2 1 新闻
3 2 新闻下级

如果知道id为2了,怎么一次搜索得出 “新闻 新闻下级”呢??

------解决方案--------------------
$id= 2;
$sql = "select * from tbl_name where id=$id or tid=$id";

如果还有下下级,就不好使了,要递归

------解决方案--------------------
递归

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn