Jump to content
php.lv forumi

Tree struktura datubazei


zimulis
 Share

Recommended Posts

To var darīt ar nested set struktūru:

http://dev.mysql.com/tech-resources/articl...hical-data.html

http://www.developersdex.com/gurus/articles/112.asp

 

Tad visus viena apakšzara bērnus dabūt būs tik vien kā:

SELECT node.*
FROM tabule AS node, tabule AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt AND parent.id = $root_id
ORDER BY node.lft;

Link to comment
Share on other sites

Diezgan briesmīgi - it īpaši, ja tabulā būs pavairāk ieraksti.

Un kamdēļ tu taisi to pirmo foreach ciklu meklējot to $pid? Masīvam pēc atslēgas var tikt klāt ar kvadrātiekavām:

  function ShowTree($tree, $pid = 0)
 {
echo "<ul>";
if (array_key_exists($pid, $tree))
{
  $root = $tree[$pid];
  if (count($root) != 0)
  {
	foreach ($root as $key => $title)
	{
	  echo "<li>{$title}";
	  ShowTree($tree, $key);
	  echo "</li>";
	}
  }
}
echo "</ul>";
 }

Link to comment
Share on other sites

Web Developer, kas tev nav skaidrs no tipiskākās parent_id koka struktūras?

id, name, parent_id

 

Un ko vajag manuprāt viņš ļoti skaidri pateica - dabūt visus viena ID bērnus visos līmeņos. Tb visus ierakstus konkrētajā apakškokā.

Link to comment
Share on other sites

  • 3 weeks later...
To var darīt ar nested set struktūru:

http://dev.mysql.com/tech-resources/articl...hical-data.html

http://www.developersdex.com/gurus/articles/112.asp

 

Tad visus viena apakšzara bērnus dabūt būs tik vien kā:

SELECT node.*
FROM tabule AS node, tabule AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt AND parent.id = $root_id
ORDER BY node.lft;

 

 

A ja napieciessams izvilkt viena ID visus bernus, mazbernus, mazzmazberbus u.t.t. vardu sakot Visu kas ietilpst saja zara??

 

Datubaze:

 

ID | Left |right| level

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
 Share

×
×
  • Create New...