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

WBOY
Release: 2016-06-13 10:37:49
Original
803 people have browsed it

如果知道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";

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!