The API returns the following categories:
[1] => Array ( [category_id] => 14308 [parent_id] => 14308 [level] => 0 ) [2] => Array ( [category_id] => 179836 [parent_id] => 14308 [level] => 1 ) [3] => Array ( [category_id] => 230022 [parent_id] => 179836 [level] => 2 )
And I need to insert them into the database like this:
βββββββββββββββ¦ββββββββββββ β category_id β parent_id β β ββββββββββββββ¬ββββββββββββ£ β 14308 β 0 β β 179836 β 14308 β β 230022 β 179836 β βββββββββββββββ©ββββββββββββ
... which is easy, but the category_to_path table is complicated, and I cannot understand. It should be like this:
βββββββββββββββ¦ββββββββββ¦ββββββββ β category_id β path_id β level β β ββββββββββββββ¬ββββββββββ¬ββββββββ£ β 14308 β 14308 β 0 β β 179836 β 14308 β 0 β β 179836 β 179836 β 1 β β 230022 β 14308 β 0 β β 230022 β 179836 β 1 β β 230022 β 230022 β 2 β βββββββββββββββ©ββββββββββ©ββββββββ
This is what I still have:
$path_ids; for ($i=0; $i <= ($category->CategoryLevel-1); $i++) { // -1 cause the API returns a non zero-based level $path_ids[$i]['category_id'] = $category->CategoryID; if ($category->CategoryLevel-1 == $i) { $path_ids[$i]['path_id'] = $category->CategoryParentID[0]; } elseif ($category->CategoryLevel-1) { // ? } $path_ids[$i]['level'] = $i; }
php mysql
3zzy
source share