Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/4711-parent-fetching/
Share on other sites

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.)
Link to comment
https://forums.phpfreaks.com/topic/4711-parent-fetching/#findComment-16495
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.