scrappy
05-20-2009, 07:34 PM
Brief description of tables:
part table: id, nameid and ids of parts. if there are multiple sub-parts for a part, then the name appears multiple times, each time with an id of the sub-part. So it's easy to find the complete list of sub-parts for a part.
eg:
a,b,c
1,1,1
2,2,2
3,1,3
4,2,3
where 'a' is the auto-increment field for the part table
'b' is the part id
'c' is the name id.
So when a part is entered (eg. 'part1'), a list of sub-parts that make up that part is presented (assume 'part1' = 3, so 1 & 2 are presented, showing that subpart1 and subpart2 make up that part), then user can click on each sub-part to get all the information.
Now management want multiple part numbers which are exactly the same set of sub-parts. This is easy, we can extract sub-parts from a previous part which is setup and apply them to the new part:
5,1,4
6,2,4
However, in the future if another sub-part is added to a part, it will not be automatically added to the other parts which are identical is all but name.
Since these additional parts are basically just aliases of existing parts, we can create another table (lets call it aliases) which matches a name id to a part id (so we lookup partid4 directly), or one name to another name (nameid4=nameid3, then lookup nameid3 in the part table). partid lookups will be quicker as the auto incremented column is indexed and unique, and I can see some time in the future, management wanting a part to be the contents of another part plus some sub-parts.
So, lets ignore names for now, if we change the first type like so:
a,b,c
1,1,1 [sub part 1]
2,2,2 [sub part 2]
3,1,3 [part id 3 contains sub part 1]
4,2,3 [and also sub part 2]
5,5,4 [sub part 3]
6,3,5 [part id 6 contains part id 3]
7,5,5 [plus sub part 3]
That looks nasty doesn't it? Referencing an id that just points to other, and doesn't even include all of them.
I know I can solve this problem with multiple select queries and loops in php, but I really want as much as possible in the sql side and less eating cpu cycles parsing php code.
Any ideas from other people? I'm thinking there must be an easier way.
I can make slight changes to the database and structure, along with code alterations, but don't really want to rewrite the entire system to use it.
One last thing: The server is MySQL 4.1.
part table: id, nameid and ids of parts. if there are multiple sub-parts for a part, then the name appears multiple times, each time with an id of the sub-part. So it's easy to find the complete list of sub-parts for a part.
eg:
a,b,c
1,1,1
2,2,2
3,1,3
4,2,3
where 'a' is the auto-increment field for the part table
'b' is the part id
'c' is the name id.
So when a part is entered (eg. 'part1'), a list of sub-parts that make up that part is presented (assume 'part1' = 3, so 1 & 2 are presented, showing that subpart1 and subpart2 make up that part), then user can click on each sub-part to get all the information.
Now management want multiple part numbers which are exactly the same set of sub-parts. This is easy, we can extract sub-parts from a previous part which is setup and apply them to the new part:
5,1,4
6,2,4
However, in the future if another sub-part is added to a part, it will not be automatically added to the other parts which are identical is all but name.
Since these additional parts are basically just aliases of existing parts, we can create another table (lets call it aliases) which matches a name id to a part id (so we lookup partid4 directly), or one name to another name (nameid4=nameid3, then lookup nameid3 in the part table). partid lookups will be quicker as the auto incremented column is indexed and unique, and I can see some time in the future, management wanting a part to be the contents of another part plus some sub-parts.
So, lets ignore names for now, if we change the first type like so:
a,b,c
1,1,1 [sub part 1]
2,2,2 [sub part 2]
3,1,3 [part id 3 contains sub part 1]
4,2,3 [and also sub part 2]
5,5,4 [sub part 3]
6,3,5 [part id 6 contains part id 3]
7,5,5 [plus sub part 3]
That looks nasty doesn't it? Referencing an id that just points to other, and doesn't even include all of them.
I know I can solve this problem with multiple select queries and loops in php, but I really want as much as possible in the sql side and less eating cpu cycles parsing php code.
Any ideas from other people? I'm thinking there must be an easier way.
I can make slight changes to the database and structure, along with code alterations, but don't really want to rewrite the entire system to use it.
One last thing: The server is MySQL 4.1.