Welcome Guest, Not a member yet? Register   Sign In
Unable to return array from function
#3

[eluser]Unknown[/eluser]
Hi Dam1an, many thanks for replying. Here's the full function:
Code:
function getparent ($id, $breadcrumb=array()) {
$this->db->where('id', $id);
$Q = $this->db->get('categories');
$row =     $Q->row_array();
// Add the category name to string
// Don’t add a | to the first category.
if (count($breadcrumb) == 0) {
    $breadcrumb = array();
    $breadcrumb[count($breadcrumb)]=$row['name'];
}
else {
    $breadcrumb[count($breadcrumb)]=$row['name']. "|";
}
// Figure out if our category has a parent category or not.
$this->db->select('parentid','name');
$this->db->where('id', $id);
$Q = $this->db->get('categories');
$row = $Q->row_array();
// If this value is 0, we are at the top of the tree…otherwise call the function again.
$parentCat = $row['parentid'];      
if ($parentCat == 0)      {
      // This is our base case, there is no parent category.
    print_r($breadcrumb);
    return $breadcrumb;
}
else {
      // This is our recursive function call.        
      $this->getparent($parentCat, $breadcrumb);
      }
}


Messages In This Thread
Unable to return array from function - by El Forum - 05-20-2009, 02:09 AM
Unable to return array from function - by El Forum - 05-20-2009, 02:41 AM
Unable to return array from function - by El Forum - 05-20-2009, 04:10 AM
Unable to return array from function - by El Forum - 05-24-2009, 07:35 AM
Unable to return array from function - by El Forum - 05-24-2009, 08:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB