The Little Guy Posted April 19, 2010 Share Posted April 19, 2010 I am going to build a function that gets an id from a table. I have a second table that has categories, with three columns: + id + parent + name + the id passed to the function will match the id column from above, then that id will have a parent id, which matches another row from the same table as the above three columns, and so on and so forth. Basically I want to loop through this until parent equals 0, and there is more than one parent that equals 0 in the table (I have three at the moment). So, lets say I pass 10 to the function, the returned MySQL row would be: + 8 + 0 + Internet + if I pass "3" to it, I would get: + 2 + 0 + Windows + parent of one row equals id of another row in the same table. I hope that all makes sense... Link to comment https://forums.phpfreaks.com/topic/199032-findget-root/ Share on other sites More sharing options...
ignace Posted April 19, 2010 Share Posted April 19, 2010 And your question is..? Link to comment https://forums.phpfreaks.com/topic/199032-findget-root/#findComment-1044705 Share on other sites More sharing options...
The Little Guy Posted April 19, 2010 Author Share Posted April 19, 2010 Basically I want to loop through this until parent equals 0 how do I do that (I would like to use only one query if possible)? Link to comment https://forums.phpfreaks.com/topic/199032-findget-root/#findComment-1044710 Share on other sites More sharing options...
ignace Posted April 19, 2010 Share Posted April 19, 2010 Take a look at http://dev.mysql.com/tech-resources/articles/hierarchical-data.html Link to comment https://forums.phpfreaks.com/topic/199032-findget-root/#findComment-1044733 Share on other sites More sharing options...
The Little Guy Posted April 20, 2010 Author Share Posted April 20, 2010 those examples didn't help, I don't have a left and right in my database, any suggestions? Link to comment https://forums.phpfreaks.com/topic/199032-findget-root/#findComment-1044966 Share on other sites More sharing options...
ignace Posted April 20, 2010 Share Posted April 20, 2010 those examples didn't help, I don't have a left and right in my database Correct. But you do have an Adjacency List Model (parent, child) and the article discusses that model. A probably better read would be http://www.sqlsummit.com/AdjacencyList.htm that not only explains it but also gives you a better approach. Link to comment https://forums.phpfreaks.com/topic/199032-findget-root/#findComment-1045089 Share on other sites More sharing options...
The Little Guy Posted April 20, 2010 Author Share Posted April 20, 2010 It had no selects... Link to comment https://forums.phpfreaks.com/topic/199032-findget-root/#findComment-1045236 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.