Hi all.
I thought I might have achieved my first bit of real PHP programming but I've come unstuck a little somewhere :/
In the new books centre box I have already succeeded in adding the author's name below the book title, but I want to go one step further and also display the genre (category) thus:
A Winter's Tale
by
Trisha Ashley
(Chick Lit)
We operate on a maximum of three category/sub-category levels: Genre ==> Author ==> Series Name (Category ==> Sub-category ==> Sub-sub-category) so in the above example A Winter's Tale is stored in Chick-Lit ==> Trisha Ashley.
If I just use the standard function: zen_get_products_category_id then this would return as:
A Winter's Tale
by
Trisha Ashley
(Trisha Ashley)
so I am part-way through programming a top-level extraction function which is where it's gone a bit pear-shaped!
This book has a master category ID of 5 (Trisha Ashley) with a parent category ID of 4 (Chick-Lit).
In includes/modules/new_products.php I added this line:
$new_category_master_id = zen_get_products_category_id($new_products->fields['products_id']);
this correctly returns $new_category_master_id as 5
going one step further to now try to extract the parent ID I added:
$new_toplevel_genre_id = zen_get_toplevel_category_id($new_category_master_id);
and in /includes/functions/functions_lookups I added this function:
/* DB#1 BEGIN - extract the top-level genre
-
TABLES: categories
*/
function zen_get_toplevel_category_id($this_category_id) {
global $db;
global $is_toplevel_category;
global $this_parent_id;
$is_toplevel_category = $this_category_id;
$this_parent_id = 9;
do {
$the_toplevel_category_query = "select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . $is_toplevel_category . "'";
$the_toplevel_category = $db->Execute($the_toplevel_category_query);
$is_toplevel_category = $the_toplevel_category->fields['categories_id'];
$this_parent_id = $the_toplevel_category->fields['parent_id'];
} while ($this_parent_id >0);
return $is_toplevel_category;
}
/* END DB#1 */
Now I was hoping this function would keep looping until the parent_id resolves to 0 giving me the ID of the top level category - but it is just returning a null value.
Would somebody please be able to advise me where I have gone wrong?
Thanks in advance