I do not know why my code does not work. I guess either something wrong with the __construct or something with complete idea. I tried to search Internet and never be able to find an example of 2d and 3d array object.
Code: Select all
<?php
class Linkitem
{ private $user_id;
private $baseCateList; // This 2 dimensional array.
private $baseLinkList; // This 3 dimensional array.
public function __construct($u=null)
{ $this->reconstruction($u);
}
public static function reconstruction($u)
{ $link = new Linkitem();
$link->user_id = $u;
$link->assignBaseCateList($link->lang_id);
$link->assignBaseLinkList($link->baseCateList);
return $link;
}
public static function assignBaseCateList($uid)
{ $query = sprintf( ' SELECT ID_CATEBASE ' .
' , TITLE_1 ' .
' FROM %sCATES_BASE ' .
' WHERE ID_LANGUAGE = %d ' .
, DB_TBL_PREFIX
, $uid
);
$result = mysql_query($query, $GLOBALS['DB']);
while($row = mysql_fetch_array($result))
{ $baseCateList[] = array( "id_catebase" => $row['ID_CATEBASE']
, "title_1" => $row['TITLE_1']
);
};
mysql_free_result($result);
}
public static function assignBaseLinkList($baseCateList)
{ for ($i=0; $i<count($baseCateList); $i++)
{ $baseLinkList[$i] = $this->getEachBaseLinkList($baseCateList['id_catebase']);
};
}
public static function getEachBaseLinkList($baseCate_id)
{ $eachBaseLinkList = Array();
$query = sprintf( ' SELECT URL ' .
' , TITLE ' .
' FROM %sLINKS_BASE ' .
' WHERE ID_CATEBASE = %d ' .
, DB_TBL_PREFIX
, $baseCate_id
);
$result = mysql_query($query, $GLOBALS['DB']);
while($row = mysql_fetch_array($result))
{ $eachBaseLinkList[] = array( "url" => $row['URL']
, "title" => $row['TITLE']
);
};
mysql_free_result($result);
return $eachBaseLinkList;
}
} // End of class.
?>