FrostiE Posted March 11, 2006 Share Posted March 11, 2006 Ok, got another problem, should be my last :-D.Anyways, what im wanting to do, if find all parents of a single entry, basically, for a bread crumb. Now I want them seperated by a "," sign or something like that, so I can explode them into a array at a later stage when I fetch them from the database.The code here is similar to the code I was helped with earlier, but just a little changed[code]function listparents ($id) { include("db.inc"); $res = mysql_query ("SELECT id, parent FROM proj WHERE id = '$parent' ORDER BY id"); while (list($id, $parent) = mysql_fetch_row($res)) { $parents = $parents.",".$id; listparents($parent); } }[/code]if I say use [code]listparents ($row['id']);[/code]and add a echo line to the bottom of the listparents function, it give me exactly what I want, exept with a , at the beginning. The only problem is a dont know how to get the final result being say : 15, 19, 32, 45 back to the original function, to add it to the database.Any help is really appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/4711-parent-fetching/ Share on other sites More sharing options...
Barand Posted March 11, 2006 Share Posted March 11, 2006 No need to store derivable data in the db. You can get the breadcrumbs with[code]include 'db.inc.php';function breadcrumbs ($id, &$p) { $res = mysql_query ("SELECT id, name, parent FROM proj WHERE id = '$id'"); list($id, $name, $parent) = mysql_fetch_row($res); array_unshift ($p, $name); if ($parent > 0) breadcrumbs($parent, $p);}$id = 10;$parents = array();breadcrumbs (10, $parents);echo join (' » ', $parents);[/code](BTW, name your include files as ".php" so they can't be browsed.) Quote Link to comment https://forums.phpfreaks.com/topic/4711-parent-fetching/#findComment-16495 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.