Page 1 of 1
Catagory Design
Posted: Fri Jun 23, 2006 5:59 pm
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!

Posted: Fri Jun 23, 2006 6:00 pm
by feyd
huh? Examples?
Posted: Fri Jun 23, 2006 6:21 pm
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
Posted: Fri Jun 23, 2006 6:50 pm
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.
Posted: Fri Jun 23, 2006 6:53 pm
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.
Posted: Fri Jun 23, 2006 7:41 pm
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.
Posted: Fri Jun 23, 2006 7:46 pm
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'];
}
Posted: Fri Jun 23, 2006 8:24 pm
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?
Posted: Fri Jun 23, 2006 8:28 pm
by feyd
forum's
Posted: Fri Jun 23, 2006 8:34 pm
by LiveFree
Works like a charm!
Thanks!