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: [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

Re: [Perchpole] Find My Siblings!

By Dave - June 1, 2012

Hi Perch,

That makes sense. Hope the code I provided helps.

getRecords() does have a bit of overhead, but servers are generally very fast. There's always the balance between programmer hours and server resources. I usually code whatever is easiest and then optimize later if there's a need due to constraints on server resources.

The biggest problem people run into is loading too many records into memory and processing them in PHP instead of Mysql, or calling a mysql query in a loop.

If you'd like to get some feedback from time to time on different ways to do things or if there's a more efficent way, feel free to post.

Cheers!
Dave Edis - Senior Developer
interactivetools.com