Tom Jakobsen wrote:
> Does any1 know what to do to show the department tree for a item??
Tree? I'm gonna take a guess that you're interested in a navbar
like Yahoo does. I use the following code in my item screen:
//get item info
$Item = GetItemInfo($item);
if( !isset($department) )
{
//get the department for this item
$department = $Item["Department"][0];
}
$department = intval($department);
// This seems pretty expensive but I can't
// come up with any better way.
readtable($deparray, "SELECT ID, d.* FROM department d");
$bar = "";
$sep = "";
$parent = $department;
while ($parent && $deparray[$parent]["Parent"]) {
$url = ScreenURL("department", FALSE
, array("department" => $parent));
$bar = "<a href=\"$url\">"
. $deparray[$parent]["Name"]
. "</a>" . $sep . $bar;
$sep = " > ";
$parent = $deparray[$parent]["Parent"];
}
print $bar . "<p>\n";
You can replace readtable() with something of your own design.
It builds $deparray as an array of department records indexed
by the department id. Hmm, or I guess you can just use mine:
/*
** readtable: fill array with table. First field
** will be used as the index, all fields will be
** stored as value unless a specific field-name
** or field number is given.
*/
function readtable(&$array, $sql, $field = "") {
$r = mysql_query($sql);
if ($r) {
while ($row = mysql_fetch_array($r)) {
if ($row[0] != "" && $field != "") {
$array[$row[0]] = $row[$field];
} elseif ($row[0] != "") {
$array[$row[0]] = $row;
} elseif ($field != "") {
$array[] = $row[$field];
} else {
$array[] = $row;
}
}
} else {
$array = array();
}
}
--
Paul Chamberlain, [EMAIL PROTECTED]
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Site: http://www.working-dogs.com/freetrade/
Problems?: [EMAIL PROTECTED]