Find My Siblings!

4 posts by 2 authors in: Forums > CMS Builder
Last Post: June 1, 2012   (RSS)

By Perchpole - May 31, 2012

Hello, All -

I'm putting togeter some code with which I want to return the number(s) of all the siblings related to the $selectedCategory.

If I wanted to find the parent I would do this:

<?php $parentCategory = mysql_get("category", $selectedCategory['parentNum']); ?>

Can I do something equally simple to return the siblings?

:0)

Perch

Re: [Perchpole] Find My Siblings!

By Dave - June 1, 2012

Hi Perch,

Have you seen the getCategories() function and review all it's options? It does a lot of this for you when you need to create nested menus, etc.

Otherwise, if you need to do something not supported by that here's some (untested) code:

$siblingWhere = "parent = '" .mysql_escape($selectedCategory['parentNum']). "'";
$siblingWhere .= " AND num != '" .mysql_escape($selectedCategory['num']). "'";
$siblingCategories = mysql_select('category', $siblingWhere);


Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Find My Siblings!

By Perchpole - June 1, 2012

H, Dave -

Thanks for the code.

My sites tend to be underpinned by a core set-up of getRecords() calls. In addition to this, if a page design requires some kind of special code, which I can't invoke from my core getRecords() calls, I try to rely on the kind of small "snippets" you've just given me above.

My reasoning for this is that I "assume" all getRecords calls are pretty heavy in terms of overhead. I feel I should avoid using any more than I have to unless absolutely necessary (a last resort).

I'm also uncomfortable about using loops to filter through a 100+ records in the hope of matching just one or two! Again, my assumption is that this would be a waste of resources.

Now, of course, I might be completely wrong - but I'm keen to learn!

:0)

Perch