Jump to content
#StayAtHome ×

glennnall

Members
  • Content Count

    17
  • Joined

  • Last visited

Community Reputation

0 Neutral

About glennnall

  • Rank
    Member
  • Birthday 02/10/1961

Contact Methods

  • Website URL
    http://glennnall.com

Profile Information

  • Gender
    Male
  • Location
    Atlanta, GA
  1. I had a problem with defining the beginning of a branch: so i did this: I put a Start ['s'] toggle, 1/0, in ASSOCS ASSOCS p_id a_id s p_to_a a_to_p 1 2 1 employs worked for 1 3 0 knows knows 3 4 0 workedwith worked with 4 6 0 knows knows 5 3 1 brother to sister-in-law to 6 7 1 wife of husband of 7 3 0 knows knows 5 1 0 test test_ dug it out in my query (a.s AS s): SELECT a.p_id, a.a_id, CONCAT(p1.fname,' ', p1.lname) as name1, p_to_a, CONCAT(p2.fname,' ', p2.lname) as name2, a.s AS s, a.info FROM assocs a INNER JOIN persons p1 ON p1.person_id = a.p_id INNER JOIN persons p2 ON p2.person_id = a.a_id stored it and called it in place of the $level switch: if (!isset($data[$pid])) { return; } if (in_array($pid, $processed)) return; // prevent circular references $processed[] = $pid; if ($data[$pid]['s']==1) { echo "<div class=''>{$data[$pid]['name']}</b></div>"; } right, I can't believe it worked, either. You're the best, Barand. You've helped me a lot. Now I'm ready to take this thing on the road...
  2. SOLUTION: Instead of adding the field to PERSONS, I added put it in ASSOCS: p_id a_id p_to_a a_to_p info 1 2 employs worked for "info..." 1 3 knows knows (null) 3 4 worked with worked with (null) SELECT a.p_id, a.a_id, CONCAT(p1.fname,' ', p1.lname) as name1, p_to_a, CONCAT(p2.fname,' ', p2.lname) as name2, a.info FROM assocs a INNER JOIN persons p1 ON p1.person_id = a.p_id INNER JOIN persons p2 ON p2.person_id = a.a_id the output ($nf, 'info' => $nf, $data[$pid]['info'], $adata['info']): $data = []; $res = $db->query($sql); while (list($pid, $aid, $n1, $ass, $n2, $nf) = $res->fetch_row()) { if (!isset($data[$pid])) { $data[$pid] = [ 'name' => $n1, 'assocs' => [], 'info' => $nf ]; } $data[$pid]['assocs'][$aid] = ['name' => $n2, 'rel' => $ass, 'info' => $nf]; } $processed=[]; function listAssociates($pid, &$data, &$processed, $level) { if (!isset($data[$pid])) { return; } if (in_array($pid, $processed)) return; // prevent circular references $processed[] = $pid; if ($level==0) { if ($data[$pid]['info'] != '') { echo "<div class=''>{$data[$pid]['name']}</b></div><div style='margin-left:0px;'>{$data[$pid]['info']}</div>"; } else { echo "<div class=''>{$data[$pid]['name']}</b> » </div>"; } } // $indent = str_repeat(' ', $level*10); $indent = ($level*25); $indent = ($indent+25)."px"; foreach ($data[$pid]['assocs'] as $aid=>$adata) { echo "<div style='margin-left:$indent'>{$adata['info']}</div><div style='margin-left:$indent'>{$adata['rel']} <b>{$adata['name']}</b></div>\n"; listAssociates($aid, $data, $processed, $level+1); } }
  3. ah - I think I've got it - i can just call the function as needed? listAssociates(1, $data, $processed, 0); listAssociates(6, $data, $processed, 0);
  4. Thanks so much, and I apologize for being a pest - the one issue I'm having with this is how to denote where a new branch starts over at level '0' within the loop (see my image in the original question). I certainly don't think it's necessary to run a new query for each branch...?
×
×
  • 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.