Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1639 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Displaying Categories/Sub-Categories

Thread title: Displaying Categories/Sub-Categories
Closed Thread    
    Thread tools Search this thread Display Modes  
02-15-2007, 08:56 PM
#1
Zara is offline Zara
Status: Member
Join date: Apr 2006
Location:
Expertise:
Software:
 
Posts: 249
iTrader: 9 / 100%
 

Zara is on a distinguished road

  Old  Displaying Categories/Sub-Categories

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...

02-17-2007, 04:03 AM
#2
Zara is offline Zara
Status: Member
Join date: Apr 2006
Location:
Expertise:
Software:
 
Posts: 249
iTrader: 9 / 100%
 

Zara is on a distinguished road

  Old

Wow, a little sleep and it came easy... I simply had order of the template variables wrong.

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed