Need some help with nested loops.....
Posted: Wed Mar 07, 2007 4:28 pm
pickle | Please use
What I need to do is display menus like:
TYPE NAME
-SUBCATEGORY NAME
-ARTICLE
-ARTICLE
-SUBCATEGORY 2 NAME
-ARTICLE
-ARTICLE
TYPE NAME 2
-SUBCATEGORY NAME
-ARTICLE
-ARTICLE
and so on. I'm pretty much a novice with PHP and don't really know how to approach sorting the results. I know I should use nested loops so if anyone can provide me with some sample code, suggestions, or even a tutorial then I would greatly appreciate it. Thanks!
pickle | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Here is the query that will get all of the necessary info:
[syntax="sql"]SELECT * FROM D_ARTICLES LEFT JOIN D_SUB_CAT ON D_ARTICLES.D_SUB_CAT_ID=D_SUB_CAT.D_SUB_CAT_ID LEFT JOIN D_CAT ON D_SUB_CAT.D_CAT_ID=D_CAT.D_CAT_ID WHERE D_ARTICLES.D_A_VISIBLE='1' AND D_ARTICLES.D_TYPE_ID='2' AND D_CAT.D_CAT_ID='2' ORDER BY D_CAT.D_CAT_ID, D_SUB_CAT.D_SUB_CAT_IDTYPE NAME
-SUBCATEGORY NAME
-ARTICLE
-ARTICLE
-SUBCATEGORY 2 NAME
-ARTICLE
-ARTICLE
TYPE NAME 2
-SUBCATEGORY NAME
-ARTICLE
-ARTICLE
and so on. I'm pretty much a novice with PHP and don't really know how to approach sorting the results. I know I should use nested loops so if anyone can provide me with some sample code, suggestions, or even a tutorial then I would greatly appreciate it. Thanks!
pickle | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]