Artifacts Gallery Guilds Search Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining?
a Summer day - @539.84
Activity rating: Four Stars Posts & Arts: 55/1k.beats ~ Boop! The forum will close in 461.beats! Random | Recent Posts | Guild Recents
News: :wizard: You can make anything on the web! :wizard: Guild Events: There are no events!

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


« previous next »
Pages: [1] Print Embed
Author Topic: PHP Help - Rendering Subcategories and Categories  (Read 1554 times)
Dreamwings
Full Member
***
View Profile WWW


Professional-grade yapper and late to the party
⛺︎ My Room

Artifacts:
Sealiously Cool User AwardJoined 2024!
« on: a Summer night » Embed

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

https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/fdcb5a9a-dca5-480e-991b-7ebf834830fb/di5tve2-76ace55e-2c6e-4c95-81de-eb3b509209b3.gif?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7InBhdGgiOiJcL2ZcL2ZkY2I1YTlhLWRjYTUtNDgwZS05OTFiLTdlYmY4MzQ4MzBmYlwvZGk1dHZlMi03NmFjZTU1ZS0yYzZlLTRjOTUtODFkZS1lYjNiNTA5MjA5YjMuZ2lmIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmZpbGUuZG93bmxvYWQiXX0.GkpdD2gNSdVBF_R_lqvwKNqfBBzIzWoPiTMnZ6BwRdM<- 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:
ThunderPerfectWitchcraft
Hero Member ⚓︎
*****
View Profile WWWArt


Here be dragons
⛺︎ My Room

Artifacts:
Visited on Melon's 10th Anniversary!I got robbed by Dan Q on Melonland!Great Posts PacmanThanks for being rad!First 1000 Members!Joined 2023!
« Reply #1 on: a Summer day » Embed

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


Artifact Swap: Spell: Rain Storm (makes the player who holds this immune to fire magic)
Pages: [1] Print Embed 
« previous next »
 

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021 | Privacy Notice | Send Feedback | Supporters ♥ 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
@000 MelonLand Zap! Want to Login or Join ? Forum Art Hub Chat Webring Editor Recent Edits Tenement Arcade Web Guides Graphics Catalogue Wiki Newsletters Image Stream
Melon's Sites TamaNotchi Textures PixelSea GifyPet MoMG Ozwomp Online Loom Videos Leaky Webring Melonking
Tools Melon Software ArtHub Embed Maker ML Passports
Outlinks Frutiger Aero Forum Onio Club m15o's Web Services 32Bit Cafe iMood Webrings Internet Phone Book HTML Energy Declarations Hackers & Designers
Minecraft: Online
Join: craft.melonking.net