Home Events! Entrance Everyone Wiki Search Login Register

Welcome, Guest. Please login or register. - Thinking of joining the forum??
November 23, 2024 - @438.26 (what is this?)
Forum activity rating: Three Stars Posts: 31/1k.beats Unread Topics | Unread Replies | My Stuff | Random Topic | Recent Posts    Start New Topic
News: :eyes: ~ Inconvenience is counterculture ~ :eyes:

+  MelonLand Forum
|-+  World Wild Web
| |-+  ✁ ∙ Web Crafting
| | |-+  ☔︎ ∙ I need Help!
| | | |-+  PHP Help - Rendering Subcategories and Categories


« previous next »
Pages: [1] Print
Author Topic: PHP Help - Rendering Subcategories and Categories  (Read 224 times)
Dreamwings
Jr. Member
**


Professional-grade yapper and late to the party

⛺︎ My Room

View Profile WWW

Sealiously Cool User AwardJoined 2024!
« on: July 17, 2024 @225.83 »

Hewwo! Not sure if there are many people here experienced with PHP but thought I would ask anyways. I want to make a system for my site that will let me post to it and automatically generate the page and RSS feed for it (because I am NOT manually formatting all of those dates), as well as fill out the writing page with all of said writings, categorized and everything. Now, filling it out from the database is easy but what I am having a hard time doing is the categorizing.
The system I was thinking was just having one table and then one column for category and then one for subcategory. If Subcategory is Null, it just goes above all the subcategories but under the category title. This is generally what I have in mind visually (basically my existing layout but automatic).
But I am having trouble actually pulling it off. It's not that I think it is nessicerily technically impossible, but the logic isn't clicking. And I don't have any other ideas logically either. I could.... possibly make another database that is just all the subcategories and then list only the ones in there + all of the ones with no subcategory, but I think another table just to store that might be a bit much no?
Another idea was to just SELECT all the ones under the category/subcategory and fill it out like that but again, would require me to edit the homepage every time I had a new subcategory or category to make a new section for it and I am trying to have it be as self-sustaining as possible.
Sorry if I am not explaining this well btw, I am self-taught and I don't really talk to other devs much so I don't know the lingo and proper terminology for these things. I can try to elaborate if it isn't making any sense.
Logged

<- Feed this guy please, they're so humgry
If I sound angry I'm probably not unless I say so. I'm just really really blunt. :dog:
My site is down for now please ignore the link lol
ThunderPerfectWitchcraft
Sr. Member ⚓︎
****


Here be dragons

⛺︎ My Room

View Profile WWW

Thanks for being rad!First 1000 Members!Joined 2023!
« Reply #1 on: July 17, 2024 @560.76 »

Hi.
You are on the right way.

Give every entry a column with category, and set a variable with a category. Before echoing it, just make a if check for the category, and a (evadable) if check for the subcategory.
Code
if($entryCategory==$SelectedCategory)
{

if(($entrySubCategory==$SelectedSubCategory) || ($entrySubCategory==0))
{
echo $entry;
}

}

you can use get to set the selected category:
Code
$SelectedGategory=htmlentities($_GET["Category"]);

should work out.

if you want to support multiple categories, make the column a string, explode for whitespaces, and make the check using a for loop for every number existent in the string.

Code
		if($Categories!="")
		{
		$choices= explode(" ", $Options);
		$arrLength = count($choices);
		for($i = 0; $i < $arrLength; $i++) 
			{
				
				
				if($choices[$i]==$SelectedCategory)
                                     {
                                         echo $Entry; //show entry
                                         $i=$arrLength; //escape the loop
                                     }
		
			    
			 }
			   

	        }
		


Didn't test it, and php isn't my main language, but I think this should work out.
To support sub-categories, either repeat the whole process where I now echo the entry (with adjusted variables, ofc), or just treat sub-categories like normal categories internally.
Logged

Pages: [1] Print 
« previous next »
 

Vaguely similar topics! (3)

Melons critiquing and helping each other

Started by urgellxBoard ✎ ∙ Art Crafting

Replies: 22
Views: 1914
Last post August 24, 2024 @487.13
by e-
A cool avatar site (andypants.net)

Started by SilkSkullBoard ♺ ∙ Web Crafting Materials

Replies: 17
Views: 2710
Last post April 01, 2023 @105.91
by SilkSkull
Ozwomp's Voyage for Android

Started by MelooonBoard ⚛︎ ∙ MelonLand Projects

Replies: 5
Views: 136
Last post November 13, 2024 @977.81
by candycanearter07

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021, Simple Machines | Terms and Policies Forum Guide | Rules | RSS | WAP | Mobile


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery! Pixel Sea TamaNOTchi