我的数据的数据库结构
CREATE TABLE IF NOT EXISTS `folder_title` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`parent_id` int(11) DEFAULT '0',
`folder_title` varchar(100) NOT NULL,
`folder_description` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;
--
-- Dumping data for table `folder_title`
--
INSERT INTO `folder_title` (`id`, `parent_id`, `folder_title`, `folder_description`) VALUES
(1, 0, 'Blah', 'Blah Blah'),
(2, 0, 'Blah2', 'Blah Blah'),
(3, 0, 'Blah3', 'Blah Blah'),
(4, 0, 'Blah4', 'Blah Blah'),
(5, 0, 'Blah 5', 'Blah Blah'),
(6, 0, 'Blah6', 'Blah Blah'),
(7, 2, 'Blah2-1', 'Blah Blah'),
(8, 2, 'Blah2-2', 'Blah Blah'),
(9, 2, 'Blah2-3', 'Blah Blah'),
(10, 9, 'Blah2-4', 'Blah Blah'),
(11, 10, 'Blah2-2', 'Blah Blah'),
(12, 3, 'Blah2-3', 'Blah Blah'),
(13, 11, 'Blah2-4', 'Blah Blah');
我正在使用mysqli
我试过这个并没有显示任何内容。空白页。
$query =mysqli_query($conn,'SELECT
p.id as id,
p.parent_id as parent_id,
c1.id as child_id_1,
c1.folder_title as child_name_1,
c2.id as child_id_2,
c2.folder_title as child_name_2,
c3.id as child_id_3,
c3.folder_title as child_name_3,
c4.id as child_id_4,
c4.folder_title as child_name_4
FROM
folder_title p
LEFT JOIN folder_title c1
ON c1.parent_id = p.id
LEFT JOIN folder_title c2
ON c2.parent_id = c1.id
LEFT JOIN folder_title c3
ON c3.parent_id = c2.id
LEFT JOIN folder_title c4
ON c4.parent_id = c3.id
WHERE c3.id = 11');
while ($row = mysqli_fetch_array($query)){
echo $row['child_name_1'].'/'.$row['child_name_2'].'/'.$row['child_name_3'].'/'.$row['child_name_4'];
}
问题是当我在mysql中运行查询时,我可以看到正确的结果,但是当我在php中运行它时,我看不到任何结果。也许我只是做对了。 如何将变量输出到echo语句中?
我正在寻找的最终结果是传递一个文件夹ID并获取所有父母,直到父母为0.
例:
11 - 10
10 - 9
9 - 2
2 - 0父文件夹
并显示如下