Board Logo

Default closed nodes from db
bareAre - 2/16/2006 at 05:39 PM

Hi

I use the PHP/MySQL way to fill the tree, and it works just fine.

I have about 8 top level categories, and I want their sub-nodes (children) to be hidden by default and all top level nodes to be expandable.

Basically, I want the opening screen to be like this:
+ Top Level Cat 1
+ Top Level Cat 2
+ .......
+ Top Level Cat 8

I hoped I could force the top node to be a kind of sub-node and get a + sign instead of the machine symbol, but that didnA?t do it. The code is below:


Code:

function build_hierarchy($id, $vn, $idfn, $pidfn, $cfn, $lfn) {
global $cat_tbl;
if ($id == 0) echo 'var '.$vn.' = [';
$sql = "SELECT * FROM $cat_tbl WHERE $pidfn=$id";
$result = q($sql);
if (mysql_num_rows($result) == 0) return;
while ($row = mysql_fetch_assoc($result)) {
if(!$vn) echo ',';
$vn = 0;
$clink = $row[$lfn];
$cid = $row[$idfn];
echo " ['$row[$cfn]', "javascript:linkCheck('$clink')", ";
if($id == 0) echo "{'st':'0','fn':'1'}";
else echo "0";
build_hierarchy($cid, $vn, $idfn, $pidfn, $cfn, $lfn);
echo ']';
}
mysql_free_result($result);
if($id == 0) echo "];";
}


bareAre - 2/16/2006 at 06:55 PM

Found solution in demo6.


Softcomplex: http://www.softcomplex.com/
Back to forum: http://www.softcomplex.com/forum/