Storing a linked list
Hi all, I've got a table such as the following: id1 char id2 char sample data looks like this: id1 id2 1 3 2 4 3 5 5 6 6 8 And of course another table has something like: id info1 info2 info3 1 blahblahblah 2 blahblahblah I'd like to store paths to specific destinations... In other words, the path from 1 to 8 is: 1,3,5,6,8 I was thinking of creating a table called relationships start end path 1 8 {3,5,6} This would allow me to easily display the path if I know the start and end, but what it doesn't allow me to do is reuse the data. IE: say that I calculate the path from 1 to 8 as 1,3,5,6,8, and then I want to know the path from 3 to 6. even though this is already calculated, I have to recalculate it as another row... hence start end path 1 8 {3,5,6} 3 6 {5} I considered making another table, called hops, such as: start end relationshipID 1 8 1 table hops: relationshipID start end 1 1 3 1 3 5 1 5 6 1 6 8 Then I could almost reuse those hops somehow but not sure. Can anyone recommend a good way to store this data? Thanks! -Matt -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: Storing a linked list
How about: $id1 = 1; $id2 = 0; while ($id1) /** or ($id2 != 8) **/ { $sql = select * from table where id1=$id1; $row=query($sql); $id1=$row-id1; $id2=$row-id2; do_stuff(); $id1 = $id2 } On Tue, June 19, 2007 10:58, Matt Juszczak wrote: Hi all, I've got a table such as the following: id1 char id2 char sample data looks like this: id1 id2 1 3 2 4 3 5 5 6 6 8 And of course another table has something like: idinfo1 info2 info3 1 blahblahblah 2 blahblahblah I'd like to store paths to specific destinations... In other words, the path from 1 to 8 is: 1,3,5,6,8 I was thinking of creating a table called relationships start end path 1 8 {3,5,6} This would allow me to easily display the path if I know the start and end, but what it doesn't allow me to do is reuse the data. IE: say that I calculate the path from 1 to 8 as 1,3,5,6,8, and then I want to know the path from 3 to 6. even though this is already calculated, I have to recalculate it as another row... hence start end path 1 8 {3,5,6} 3 6 {5} I considered making another table, called hops, such as: start end relationshipID 1 8 1 table hops: relationshipIDstart end 1 1 3 1 3 5 1 5 6 1 6 8 Then I could almost reuse those hops somehow but not sure. Can anyone recommend a good way to store this data? Thanks! -Matt -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED] -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- Later Mogens Melander +45 40 85 71 38 +66 870 133 224 -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: Storing a linked list
Matt I'd like to store paths to specific destinations... See -- Tropashko's 'materialized modell' eg http://www.dbazine.com/oracle/or-articles/tropashko4 -- the airports example at http://www.artfulsoftware.com/mysqlbook/sampler/mysqled1ch20.html PB - Matt Juszczak wrote: Hi all, I've got a table such as the following: id1 char id2 char sample data looks like this: id1id2 13 24 35 56 68 And of course another table has something like: idinfo1info2info3 1blahblahblah 2blahblahblah I'd like to store paths to specific destinations... In other words, the path from 1 to 8 is: 1,3,5,6,8 I was thinking of creating a table called relationships startendpath 18{3,5,6} This would allow me to easily display the path if I know the start and end, but what it doesn't allow me to do is reuse the data. IE: say that I calculate the path from 1 to 8 as 1,3,5,6,8, and then I want to know the path from 3 to 6. even though this is already calculated, I have to recalculate it as another row... hence startendpath 18{3,5,6} 36{5} I considered making another table, called hops, such as: startendrelationshipID 181 table hops: relationshipIDstartend 113 135 156 168 Then I could almost reuse those hops somehow but not sure. Can anyone recommend a good way to store this data? Thanks! -Matt -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: Storing a linked list
Celko also discusses them in SQL For Smarties. Baron Peter Brawley wrote: Matt I'd like to store paths to specific destinations... See -- Tropashko's 'materialized modell' eg http://www.dbazine.com/oracle/or-articles/tropashko4 -- the airports example at http://www.artfulsoftware.com/mysqlbook/sampler/mysqled1ch20.html PB - Matt Juszczak wrote: Hi all, I've got a table such as the following: id1 char id2 char sample data looks like this: id1id2 13 24 35 56 68 And of course another table has something like: idinfo1info2info3 1blahblahblah 2blahblahblah I'd like to store paths to specific destinations... In other words, the path from 1 to 8 is: 1,3,5,6,8 I was thinking of creating a table called relationships startendpath 18{3,5,6} This would allow me to easily display the path if I know the start and end, but what it doesn't allow me to do is reuse the data. IE: say that I calculate the path from 1 to 8 as 1,3,5,6,8, and then I want to know the path from 3 to 6. even though this is already calculated, I have to recalculate it as another row... hence startendpath 18{3,5,6} 36{5} I considered making another table, called hops, such as: startendrelationshipID 181 table hops: relationshipIDstartend 113 135 156 168 Then I could almost reuse those hops somehow but not sure. Can anyone recommend a good way to store this data? Thanks! -Matt -- Baron Schwartz http://www.xaprb.com/ -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]