Wednesday, 24 April 2013

Function for DELETE ALL CHILDREN OF A PARENT CATEGORIES
function deleteChildren($parentId) {
      $lochid = new Location();
      $children = $lochid->where("parent_id", $parentId)->get();
      if (!empty($children)) {
            foreach ($children as $child) {
                $this->deleteChildren($child->id);
                $this->db->delete('countries_locations', array('id' =>$child->id));
            }
        }
    }


Function for update ALL CHILDREN VALUE WHEN PARENT IS UPDATED OF A PARENT CATEGORIES
function updateChildren($parentId) {

      $sql = "SELECT * from  xcart_categories WHERE parentid='$parentId'";
      $children = func_query($sql);
      if (!empty($children)) {
            foreach ($children as $key=>$val) {
                $childcatid = $val['categoryid'];
                $child_data = array('to_show_top_nav' =>'Y');
                func_array2update('categories', $child_data, "categoryid='".intval($childcatid)."'");
                updateChildren($childcatid);
           }
        }
    }


/* Function for create parent and child from an array */
$speed_bar = array();
$speed_bar = buildTree($speed_bar);
function buildTree(array $elements, $parentId = '')
{
        $branch = array();
        foreach ($elements as $element)
    {
            if ($element['parent'] == $parentId)
        {
            $children = buildTree($elements, $element['id']);
            if ($children) {
            $element['children'] = $children;
            }
            $branch[] = $element;
        }
    }
    return $branch;
}    


/* Code FOR GET Number of days between TWO TIME STAMP


$lastapplytime=$lastdatetimestemp;
$todaytime = time();
$diff = abs($todaytime - $lastapplytime);
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
$diff2 =  $days+($months*30);

OR

$numDays = floor(abs($lastapplytime - $todaytime)/60/60/24);

No comments:

Post a Comment

List OF BANK PAN Numbers

List OF BANK PAN Numbers Bank/Home Loan Providers PAN Number Allahabad Bank AACCA8464F Andhra Bank AABCA7375C Axis Bank...