Hi,
I’m trying to reproduce this code found here in XOJO.
What’s the best XOJO data type to use for the $path variable?
Thank you.
[code]<?php
function get_path($category_id)
{
// look up the parent of this node
$result = mysql_query("SELECT c1.parent_id,c2.category_name AS parent_name FROM category AS c1
LEFT JOIN category AS c2 ON c1.parent_id=c2.category_id
WHERE c1.category_id=’$category_id’ ");
$row = mysql_fetch_array($result);
// save the path in this array
$path = array();
//continue if this node is not the root node
if ($row['parent_id']!=NULL)
{
// the last part of the path to node
end($path);
$last_key = key($path);
$key = $last_key==0 ? 0 : $last_key+1;
$path[$key]['category_id'] = $row['parent_id'];
$path[$key]['category_name'] = $row['parent_name'];
$path = array_merge(get_path($row['parent_id']), $path);
}
return $path;
}
?>[/code]
…
<?php
for ($i=count($path)-1;$i==0;$i--)
{
echo $path[$i]['category_name']. '>';
}
?>