timmy0320 Posted March 26, 2008 Share Posted March 26, 2008 I'm working on a Category list and seem to be having issues when it comes to deleting. I really don't know where to start when deleting. Right now all I'm using is a parent_id which will ref. to it's parents ID. So when I deleted a main-category it made the sub-categories not display on my page but they were still in the database. ex: <?php $sql = "SELECT `category_id`, `name`, `description`, `count` FROM `blog_category` WHERE `parent` = '$parent' ORDER BY `name`"; $res = mysql_query($sql) or die(mysql_error()); $i = 0; while (list($category_id, $name, $description, $count) = mysql_fetch_row($res)) { $indent = str_repeat('— ', $level); $bg = ($i%2) ? 'cccccc' : 'ffffff'; echo "<tr><td bgcolor=\"#$bg\" height=\"26\"><div align=\"center\">$category_id</div></td><td>$indent$name</td> <td>$description</td><td><div align=\"center\">$count</div></td><td><div align=\"center\"><a href=\"categories.php?action=edit&id=$category_id\">Edit (disabled)</a></div></td> <td><div align=\"center\"><a href=\"categories.php?action=delete&id=$category_id\">Delete</a></div></td></tr>"; display_category_table($category_id, $level+1); $i++; } ?p Result: (category_id)$name(parent_id) (1)Computers (0) -(3)Programming(1) -(5)PHP(3) -(10)Scripts(5) -(6)HTML(3) -(4)Games(1) -(9)Call of Duty4(4) (2)Links(0) -(7)Myspace(2) -(8)Facebook(2) These are just example of what I have inputted for testing purposes. My problem is since the Parent ID's are all over the place and makes it hard to create myself a "delete" function that will delete any sub-categories under it(unless someone knows a solution) Now I was thinking of completely re-doing this slop and doing some sort of parentage column such as using the current ID's on the above example 1-3-5 (which would equal PHP). It seems a hell of a lot easier but I don't know how to do this and can't seem to find any good reading material on it. Can anyone help on the way I'm currently doing it with deleting or help me with a new method? Link to comment https://forums.phpfreaks.com/topic/98014-tree-data/ Share on other sites More sharing options...
rhodesa Posted March 26, 2008 Share Posted March 26, 2008 This is a GREAT article about managing hierarchical data: http://dev.mysql.com/tech-resources/articles/hierarchical-data.html Link to comment https://forums.phpfreaks.com/topic/98014-tree-data/#findComment-501498 Share on other sites More sharing options...
timmy0320 Posted March 26, 2008 Author Share Posted March 26, 2008 This is a GREAT article about managing hierarchical data: http://dev.mysql.com/tech-resources/articles/hierarchical-data.html Yeah, I read that a little bit ago. I'm pretty much using the top example on that page but of course then , it says it's difficult with deleting and displaying the data in certain ways, which is exactly what I'm having trouble doing. :-\ Link to comment https://forums.phpfreaks.com/topic/98014-tree-data/#findComment-501516 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.