Category Lineage from $_REQUEST call

5 posts by 2 authors in: Forums > CMS Builder
Last Post: October 18, 2011   (RSS)

Hello All -

I'm trying to derive the category lineage working backwards from a $_REQUEST function.

Let's assume the lineage is: 1:2:3

I then call category 3 using:

./index.php?category=3

I can return the category number by using:

$_REQUEST['category']

But from this point how do I workout what the parent category number is?

NB: I intend to use this code in the WHERE clause of a getRecords() call.

Thanks in advance.

:o/

Perch

Re: [Perchpole] Category Lineage from $_REQUEST call

By Jason - October 17, 2011

Hi Perch,

Once you've selected the current category, the parent number is part of that record. For example:

<?php echo $selectedRecord['parentNum']; ?>

So, in your example, if the record num of $selectedCategory is 3, then $selectedRecorc['parentNum'] would be 2.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Perchpole] Category Lineage from $_REQUEST call

By Jason - October 18, 2011

Hi Perch,

You can use the parentNum field of selectedCategory in a where clause to retrieve the parent record.

If you are using CMSB 2.08 or greater, you can use the mysql_get() function like this:

EXAMPLE:

list($categoryRecords, $selectedCategory) = getCategories(array(
'tableName' => 'categories'
));

$parent = array();

if ($selectedCategory) {
$parent = mysql_get('categories', $selectedCategory['parentNum']);
}


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Category Lineage from $_REQUEST call

Brilliant. Thanks.

:0)

Perch