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