I am having a few issues with the script below. I'm creating a simple CMS, and basically, I'm trying to incorporate 'sections' for the articles to fall under. I intend to have the main parent sections, and then allow child sections to be added to those parent sections if desired.

It's going fine for the most part, but I have run into one problem. When trying to list the child sections along with the parent section, I can't seem to get things to work properly.

I want to list sections somewhat like this:

Parent Section Name - Link to Delete
________Child Section Name - Link to Delete
________Child Section Name - Link to Delete
________Child Section Name - Link to Delete
Parent Section Name - Link to Delete

So I came up with this:

PHP Code:
<?php
// editSections.php
// List sections with ability to delete

// Hard code in include_path for localhost:
ini_set("include_path"".;C:\\wamp\\www\\cms\\");

require_once(
'includes/DbConnector.php');

$db = new DbConnector;

// get sections that are parents - no parent ID
$parent_sections $db->query("SELECT * FROM cmssections WHERE parentid = 0;");

// get sections that aren't parents - the children
$child_sections $db->query("SELECT * FROM cmssections WHERE parentid > 0;");

// list sections and their children
echo "<center>";
while(
$parent_row $db->fetchArray($parent_sections))
{
    echo 
$parent_row['name']." - <a href=\"link_to_delete\">Delete</a> <br />";
    echo 
"<indent> <!-- Does this work? otherwise, use a list or something -->";
    while(
$child_row $db->fetchArray($child_sections))
    {
        if(
$child_row['parentid'] == $parent_row['id'])
        {
            echo 
$child_row['name']." - <a href=\"link_to_delete\">Delete</a> <br />";
        }
    }
    echo 
"</indent> <!-- Does this work? otherwise, use a list or something --> <br />";
}
echo 
"</center>";

// gather all parents for selection at the creation of a new section
$parents '';
while(
$row $db->fetchArray($parent_sections))
{
    
$parents .= "<option value=\"".$row['name']."\">".$row['name']."</option>";
}

echo 
"
<br />
<h3>New Section</h3><br />
<form method=\"post\" action=\"addSection.php\">
<b>Section Name:</b> <input type=\"text\" name=\"name\" /><br /><br />
<b>Parent?</b> <select name=\"parent\">
<option selected=\"selected\" value=\"No Parent\">No Parent</option>
"
.$parents."
</select><br /><br />
<input type=\"submit\" name=\"submit\" value=\"Create Section\" />
</form>
"
;
?>
Other than the untidiness of the code, the issue I am having is with getting the child sections to list. When I ran that page, the parents listed fine, but the children aren't listed. (I view the source, and where they should be listed, the area is blank.) And I know I have children...I manually placed them in via phpMyAdmin, and they look like this:

First Section - Parent Section
ID: 1
Name: First Section
Parentid: 0

Second Section - Child Section
ID: 2
Name: Second _Child_ Section
Parentid: 1

So as you can see, the parentid matches the id of the parent, and that is what I check for in the script.

Could the problem be arising from me nesting while($child_row = $db->fetchArray($child_sections)) within while($parent_row = $db->fetchArray($parent_sections))? I kind of suspected that may show be problems, but I don't really see why it would.

Anyone have any ideas?