I have a database like so...
My PHP:
[/SIZE][/FONT]
PHP Code:
$theme->insert_nest("home", "left_blocks");
//List Categories
$query=$db->query("SELECT `id`, `name`, `parent` FROM `" . $db_prefix . "tut_categories` WHERE `parent` < '0' ORDER BY `name` ASC");
while($result = $db->fetch_array($query)) {
$theme->insert_nest("home", "left_blocks/list_categories", array
(
"CAT_ID" => $result['id'],
"CAT_NAME" => $result['name'],
"CAT_PARENT" => $result['parent']
));
$theme->add_nest("home", "left_blocks/list_categories");
//List Sub-Categories
$subqueryy="SELECT `id`, `name`, `parent` FROM `" . $db_prefix . "tut_categories` WHERE `parent` = '" . $result['id'] . "' ORDER BY `name` ASC";
$subquery =$db->query("SELECT `id`, `name`, `parent` FROM `" . $db_prefix . "tut_categories` WHERE `parent` = '" . $result['id'] . "' ORDER BY `name` ASC");
while($sub_result = $db->fetch_array($subquery)) {
$theme->insert_nest("home", "left_blocks/sub_list_categories", array
(
"SUB_CAT_ID" => $sub_result['id'],
"SUB_CAT_NAME" => $sub_result['name'],
"SUB_CAT_PARENT" => $sub_result['parent'],
"DEBUG" => $subqueryy
));
$theme->add_nest("home", "left_blocks/sub_list_categories");
}
}
$theme->add_nest("home", "left_blocks");
The Template HTML:
Code:
<!-- BEGIN left_blocks -->
<table width="200" border="0" cellspacing="0" cellpadding="5">
<tr>
<th height="25">
<div align="left">{L.Categories}
</div>
</th>
</tr>
<!-- BEGIN list_categories -->
<tr>
<td><a href="{C.url}/category.php?cid={CAT_ID}">{CAT_NAME}</a></td>
</tr>
<!-- BEGIN sub_list_categories -->
<tr>
<td><a href="{C.url}/category.php?cid={SUB_CAT_ID}">- {SUB_CAT_NAME}</a></td>
</tr>
<!-- END sub_list_categories -->
<!-- END list_categories -->
</table>
<!-- END left_blocks -->
The Output:
I've been up for 3 days now and just cannot think straight, anyone care to remind me what I'm doin' wrong? It's looping through them all for each parent category...