Catagory Design

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Catagory Design

Post by LiveFree »

Ok Peeps,

Well I have 2 tables (forums and cat) those two are linked by cat (forums) and catID (cat) which is the ID of the cat that the forum belongs in.

I need a way to put each forum in a cat without repeating the catagory.

Any advice would be very much appriciated.

Thanks! :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

huh? Examples?
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Post by LiveFree »

Catagory:

CatID: 1
CatName: Test

CatID: 2
CatName: Testing

Forums:

ForumId: 1
ForumCat: 1
ForumName: Testing

Forum ID: 1
ForumCat: 2
ForumName: Testing you!

How can I make the code so that the forum with cat 2 will come out in a different catagory BUT when I add more forums with that catagory, the catagory doesnt repeat

This is pretty much liek the way phpBB's forum display is structured
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Hey Tucker, I don't want to knitpick but it is difficult to answer you question because you use very unspecific terms.:

"How can I make the code so that the forum with cat 2 will come out in a different catagory BUT when I add more forums with that catagory, the catagory doesnt repeat "

make the code - do you simple mean "program it" or more specifically something like "build display code" or "program the code in the loop fetching the category records", etc?

come out in a different catagory - do you mean "displayed separately" or "added to an array as as different category", etc?

that catagory - meaning "cat 1" or 'cat 2"?

repeat - do you mean "displayed only once" or "not displayed twice one after the other" or "not sorted", etc?


It is not even clear whether you are fetching records from the category or forum table? People would like to help, but you need to be specific enough so they can spend their valuable time answering your question -- not trying to understand what you are asking.
(#10850)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The basic concept is keep track of the previous record's category. If it changes, output a category header. Otherwise, keep on writing out the forums.
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Post by LiveFree »

I think I know what to do know..

Have an array key be the the Cat's ID and if that key == the current Cat ID then dont print it.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

//select * from `cats` inner join `topics` .. order by `cats`.`id`

$lastcat = '';
while ($row = mysql_fetch_assoc($result)) 
{
   if ($lastcat != $row['category'])
   {
      echo $row['category'];
   }

   $lastcat = $row['category'];
}
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Post by LiveFree »

Hey JCart!

Thanks for that code, it looks promising.

But say I have 2 cat vars ($cat = the catagory ID from the forum table) and ($catID = the ID of the catagory in the cat table)

Which one would I use for $lastcat?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

forum's
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Post by LiveFree »

Works like a charm!

Thanks!
Post Reply