Jump to content

Need help with selectors


Zeka
 Share

Recommended Posts

Hi.

I am having difficulty in creating a selector query.

I have three types of pages: pathologies, diagnostics, and diagnostic categories.

Diagnostics are related to pathologies and categories by page field.

Pathologies:

id: 1 | title: one

id: 2 | title: two

id: 3 | title: three

Diagnostic Categories

id: 10 | title: cattle

id: 11 | title: pigs

id: 12 | title: poulty

Diagnostics:

id: 45 | title: one | pathologies: 1,3 | diagnostic_category: 10,

id: 46 | title: two | pathologies: 2,3 | diagnostic_category: 10, 11

id: 47 | title: three | pathologies: 1,2,3 | diagnostic_category: 10, 12

id: 48 | title: four | pathologies: 1,2 | diagnostic_category: 10

I need to list pathologies that related to specific category.

Example: 

For pigs (id:11) category it will be pathologies with ids 2, 3.

For poulty (id:12) category pathologies with ids 1, 2, 3.

Is it possible to do with selectors? 

Any help would be appreciated

Link to comment
Share on other sites

not sure about a selector, but you'd need to create some array of pathologies for each category which are assigned at the diagnostics level:

$categories = $pages->find("template=diagnostic_category");

foreach($categories as $cat) {

	$cat_paths = new Pagearray();
	$cat_diags = $pages->find("template=diagnostic, diagnostic_category=$cat");

	foreach($cat_diags as $cd) {
		$cat_paths->import($cd->pathologies);
	}

	echo $cat_paths->implode(', ', 'title');

}
  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...