Welcome Guest, Not a member yet? Register   Sign In
Help with looping sub categories
#1

[eluser]k2zs[/eluser]
I am stuck here...

I want to loop through sub categories in my view with the master catecory as a heading. I guess the best way to explain would be to show the code I tried:

Code:
<?php if (!EMPTY($SupportCategories)): ?>
<div style="margin: 10px;">
    <div style="padding: 20px; margin-top: 0px; margin-left: 40px;">
    &lt;?php foreach ($SupportCategories as $row): ?&gt;
    <h3>&lt;?php echo $row->prodName; ?&gt;</h3>
    <ul>
        &lt;?php foreach ($SupportFiles as $row): ?&gt;
        &lt;?php if ($SupportCategories['prodID'] == $SupportFiles['prodID']): ?&gt;
            <li>&lt;?php echo $row->fileName; ?&gt;</li>
        &lt;?php endif; ?&gt;
        &lt;?php endforeach; ?&gt;
    </ul>
    &lt;?php endforeach; ?&gt;
    </div>
</div>
&lt;?php endif; ?&gt;

Please help with examples and don't treat me like an idiot, I am new to CI...
#2

[eluser]k2zs[/eluser]
OK... I got it to work by changes like this:
Code:
&lt;?php if (!EMPTY($SupportCategories)): ?&gt;
<div style="margin: 10px;">
    &lt;?php foreach ($SupportCategories as $row): ?&gt;
    <div style="padding: 20px; margin-top: 0px; margin-left: 40px;">
    &lt;?php $categoryID = $row->prodID; ?&gt;
    <h3>&lt;?php echo $row->prodName; ?&gt;</h3>
    <ul>
        &lt;?php foreach ($SupportFiles as $row): ?&gt;
        &lt;?php $supportID = $row->prodID; ?&gt;
        &lt;?php if ($categoryID == $supportID): ?&gt;
            <li>&lt;?php echo $row->fileName; ?&gt;</li>
        &lt;?php endif; ?&gt;
        &lt;?php endforeach; ?&gt;
    </ul>
    </div>
    &lt;?php endforeach; ?&gt;
</div>
&lt;?php endif; ?&gt;

But I'm sure there must be a cleaner way of doing it. Any suggestions?
#3

[eluser]skunkbad[/eluser]
You might take a look at the way I implemented the category menu in Community Cart. Category data is pulled in from the database, and it is sorted then sent to the view where it is processed by a recursive function that outputs nested lists to accommodate unlimited sub-categories. It took a lot of work to make this happen, and it could be stripped out and used in another application quite easily.
#4

[eluser]k2zs[/eluser]
Wow thats fantastic help, thank you. I downloaded the app and in just a few min I was able to learn so much and yet generate more questions. I was unaware that I could use pure php files as views and build the page as a variable and then echo it. It makes it so much easier to learn from a working model. One problem I am having though is with sessions. I can log in but am always challenged for username and passwod with every link I click in the admin. After I log in I see the link I clicked but forms won't process because of this.

I come mainly from an old-school ColdFusion background and have always worked top-down as a flat file with all of the application code at the top. I did call includes to modularize my pages but thats been it. Been working with php for about 2 years and adopted the same style programming there. This MVC stuff is totally new to me and have only done it for about 3 weeks. Since then I have already put a site live where I've implemented a back end that works.

Just last night I was able to recreate an entirely different site using my first site as a starting point and it only took about 1 hour so I am hooked now Smile
#5

[eluser]k2zs[/eluser]
HA! Problem solved! I didn't change the default "mega_string".... This stuff is too cool!
#6

[eluser]skunkbad[/eluser]
[quote author="k2zs" date="1289969276"]HA! Problem solved! I didn't change the default "mega_string".... This stuff is too cool![/quote]

Hey, glad you are having fun and figuring stuff out. Pretty much every problem a person has with my app relates to their lack of properly configuring it during installation. I'm currently working on a First Data / Linkpoint gateway, and there are a lot of changes that will be on bitbucket in a couple of weeks.
#7

[eluser]skunkbad[/eluser]
[quote author="k2zs" date="1289966975"]Wow thats fantastic help, thank you. I downloaded the app and in just a few min I was able to learn so much and yet generate more questions. I was unaware that I could use pure php files as views and build the page as a variable and then echo it. It makes it so much easier to learn from a working model. One problem I am having though is with sessions. I can log in but am always challenged for username and passwod with every link I click in the admin. After I log in I see the link I clicked but forms won't process because of this.

I come mainly from an old-school ColdFusion background and have always worked top-down as a flat file with all of the application code at the top. I did call includes to modularize my pages but thats been it. Been working with php for about 2 years and adopted the same style programming there. This MVC stuff is totally new to me and have only done it for about 3 weeks. Since then I have already put a site live where I've implemented a back end that works.

Just last night I was able to recreate an entirely different site using my first site as a starting point and it only took about 1 hour so I am hooked now Smile[/quote]

I just do things my way. That doesn't mean you have to do it that way, but reflects on the flexibility of CI!




Theme © iAndrew 2016 - Forum software by © MyBB