![]() |
Foreach Loop
I'm trying loop categories so I get main category then the sub cats listed below them for a download section mod I'm building.
Here's the code thus far: PHP Code:
Steve |
And the problem is?
|
Oh sorry, the problem is that they will display but I'm not sure how to get them to display like so:
Main Cat 1 - SubCat2 | - SubCat3 - SubCat4 Main Cat 2 - SubCat5 | - SubCat6 - SubCat7 | - SubCat8 But all I get from that foreach is a list of all categories that just repeat. So maybe I'm missing something. Thanks Steve |
Why not just select all the categories and order them in an array properly in a single loop? You will be generating quite a few queries with your current method....
|
Actually, what you suggested Danny is what I'm trying but failing horribly. Any code suggestions?
|
Please provide the table structure and sample data.
|
it's a simple structure with only one level of subcategories right ?
PHP Code:
|
Something like:
PHP Code:
|
Tefra: sub_cat is no longer used, all I use now is par_cat. Here is an updated piece of code.
PHP Code:
HTML Code:
<if condition="$number_cats == '0'">do nothing<else />begin displaying sub cats</if> PHP Code:
Now the foreach confused me because I don't use sub_cat any longer, if you could redo the example using par_cat. Danny.VBT, your more than welcome to answer my questions above. Now the example code you posted I didn't understand, can you explain each portion or what its doing example wise? Thanks Steve |
I suggest you one really helpful change to calculate the total entries of each category during the add,delete,move of the download entries. This way you will save the count query.
PHP Code:
|
Thanks Tefra, will give it a go later.
EDIT: I just noticed something Tefra, in the code above you have it counting categories, why I had it that way I don't know, what I meant to count when viewing the main page you see a total number of files for that cat and all sub cats then a total for files under that main cat only. I'm still trying to figure that out, once I get the cats sorted, I'll post up my file count stuff. --------------- Added [DATE]1200524647[/DATE] at [TIME]1200524647[/TIME] --------------- Seems this line: PHP Code:
Code:
Parse error: syntax error, unexpected T_LNUMBER in /downloads.php on line 96 |
PHP Code:
|
Duh, I was just looking at similar code in another file, didn't even think about that. Thanks Dismounted.
|
sorry about the syntax error, the code above is based on my suggestion to calculate the entries of each category during the management of the categories and during the add, edit, delete and tje move of the entries.
If you decide to go with a multi-level structure the counting with queries during listing will be really ugly. If you go with this structure for example Downloads A - Downloads ab | Downloads ac You can't have it saying Downloads A total entries = 0 when the subs have entries inside. |
also shouldn't it be:
PHP Code:
|
Marco, both methods are correct.
|
Marco is correct, however, that it is a redundant check - what should be checked is if the id is negative or not, which can be done using TYPE_UINT.
|
All times are GMT. The time now is 03:07 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|