I have a note organizer and I want to make it sortable by subjects. Instead of creating multiple columns in the database ie. subject 1, subject 2, subject_3, etc. I wanted to have one subjects column and have it take multiple entries in the same column. How would I then create a page that lists all the categories? I was just thinking commas after each subject in the table.
Any ideas?
Thanks,
N8
Subject Layout
Moderator: General Moderators
Re: Subject Layout
You can use an array and the sort function in PHP.
-
peterjwest
- Forum Commoner
- Posts: 63
- Joined: Tue Aug 04, 2009 1:06 pm
Re: Subject Layout
So what you're suggesting is instead of database columns:
subject1 = 'animals'
subject2 = 'cats'
subject3 = 'cuteness'
Having:
subject = 'animals, cats, cuteness';
When PHP gets the subject from the database you can use:
$subjectArray = explode(', ',$subject);
To get an array where
$subjectArray [0] = subject1;
$subjectArray [1] = subject2;
$subjectArray [2] = subject3;
However if you're working on a large project (if you'll need to use the subjects in many ways) you may wish to consider making a separate table for each subject.
Subject table:
note = [note primary key]
subject = 'animals'
subject1 = 'animals'
subject2 = 'cats'
subject3 = 'cuteness'
Having:
subject = 'animals, cats, cuteness';
When PHP gets the subject from the database you can use:
$subjectArray = explode(', ',$subject);
To get an array where
$subjectArray [0] = subject1;
$subjectArray [1] = subject2;
$subjectArray [2] = subject3;
However if you're working on a large project (if you'll need to use the subjects in many ways) you may wish to consider making a separate table for each subject.
Subject table:
note = [note primary key]
subject = 'animals'
-
peterjwest
- Forum Commoner
- Posts: 63
- Joined: Tue Aug 04, 2009 1:06 pm
Re: Subject Layout
Yes, sorry. I mean that you should make one table called Subject which stores an entry for each subject.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Re: Subject Layout
+1 separate subject table idea.