# Id/parentid relationship

**URL:** <https://forum.kirupa.com/t/id-parentid-relationship/152058>\
**Category:** Uncategorized\
**Created:** [June 20, 2005, 9:56pm UTC](https://forum.kirupa.com/t/id-parentid-relationship/152058 "2005-06-20T21:56:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![philipip](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/philipip/32/1231_2.png) [@philipip](https://forum.kirupa.com/u/philipip)\
**Post date:** [June 20, 2005, 9:56pm UTC](https://forum.kirupa.com/t/id-parentid-relationship/152058/1 "2005-06-20T21:56:17Z")

</div>

Hi!  
im been sitting with this for a wail…  
trying to make a list of the sections after id and parnetid.

like this… [indent]‘id 0’ About  
‘id 1’ Service[indent]‘id 2’ Service 1 ‘parent id 1’[indent]‘id 3’ Service 1.1 ‘parent id 2’[/indent]‘id 4’ Service 2 ‘parent 1’[/indent]‘id 5’ Contact  
[/indent] here is the code i’ve been working whit (all day);

```auto
$result = $connector->query('SELECT ID, name, parentid FROM fm_sections ORDER BY ID');
 while ($row = $connector->fetchArray($result)) {
 	if ($row['parentid'] == '0') {
 		echo '</br>
 		Section id;&nbsp;<b>'.$row['ID'].'</b>&nbsp;&nbsp;
 		Section Name;&nbsp;<b>'.$row['name'].'</b>&nbsp;&nbsp;
		Section parent id;&nbsp;<b>'.$row['parentid'].'</b><br />';
 	}
 					
 	$result_child = $connector->query('SELECT ID, name, parentid FROM fm_sections');
						
 	while ($row_child = $connector->fetchArray($result_child)) {
 		if ($row['parentid'] > '1') {
 			if ($row['ID'] == $row_child['parentid']) {
 				echo '
 				<blockquote>
		 		Section id;&nbsp;<b>'.$row['ID'].'</b>&nbsp;&nbsp;
		 		Section Name;&nbsp;<b>'.$row['name'].'</b>&nbsp;&nbsp;
		 		Section parent id;&nbsp;<b>'.$row['parentid'].'</b>
 				</blockquote>';
 			}
 		}
 	}
 }

```

mysql tabel (if needed);

```auto
-- 
 -- Table structure for table `fm_sections`
 -- 
 
 DROP TABLE IF EXISTS fm_sections;
 CREATE TABLE fm_sections (
   ID int(4) unsigned NOT NULL auto_increment,
   name varchar(20) default NULL,
   parentid int(4) default '0',
   PRIMARY KEY (ID)
 ) TYPE=MyISAM AUTO_INCREMENT=23 ;
 
 -- 
 -- Dumping data for table `fm_sections`
 -- 
 
 INSERT INTO fm_sections VALUES (10, 'News', 0);
 INSERT INTO fm_sections VALUES (11, 'About', 0);
 INSERT INTO fm_sections VALUES (16, 'Deltakarar', 0);
 INSERT INTO fm_sections VALUES (14, 'TingOgTang', 0);
 INSERT INTO fm_sections VALUES (17, 'Bandene', 16);
 INSERT INTO fm_sections VALUES (18, 'Dirigent', 17);
 INSERT INTO fm_sections VALUES (19, 'Stykker', 17);
 INSERT INTO fm_sections VALUES (20, 'Komponist', 19);

```

hope someone can help me with this…

tanx…  
philip
