Page 1 of 1
Subject Layout
Posted: Mon Aug 03, 2009 11:33 pm
by wondernate
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
Re: Subject Layout
Posted: Tue Aug 04, 2009 12:39 am
by pcoder
You can use an
array and the
sort function in PHP.
Re: Subject Layout
Posted: Tue Aug 04, 2009 5:07 pm
by peterjwest
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'
Re: Subject Layout
Posted: Tue Aug 04, 2009 7:36 pm
by peterjwest
Yes, sorry. I mean that you should make one table called Subject which stores an entry for each subject.
Re: Subject Layout
Posted: Tue Aug 04, 2009 8:24 pm
by Ollie Saunders
+1 separate subject table idea.