We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25586
    • 105 Posts
    Hi everyone,

    I’m working on a application for my internship and I need to use the Innerjoin function.

    This is the situation:
    I have created a schema with a class called "companies" and a class called "locations".

    I can output a list of the companies names but I want to output there locations aswel in the same htmltable, like Company name, City, Address, telephone etc.

    How can I do this?

    I tried:


    $c = $modx->newQuery('companies');
    $c->innerJoin('locations');
    
    $companies = $modx->getCollection('companies', $c);
    if($companies) {
    	foreach($companies as $company) {
    		$list .= $modx->getChunk($rowTpl,$company->toArray());
    	}
    }
    


    I can make the code work when I leave out the , $c but with it the code wont output anything sad

    Anyone knows what I do wrong?
      • 25586
      • 105 Posts
      I can output the companies, but when I use $c->innerJoin(’location’, ’location’); It won’t output the fields I specified in the chuck. Do i need to use a select funtion?

      Hope someone can help me!
        • 25586
        • 105 Posts
        I got it working!

        I used the following code:
        $bedrijven = $modx->getCollection('bedrijven');
        if($bedrijven) {
        	foreach($bedrijven as $bedrijf) {
        		$x = $modx->newQuery('supdeskLocaties');
        		$x->where(array(
           			'id' => $bedrijf->id,
        		));
        		
        		$locaties = $modx->getCollection('locaties', $x);
        		
        		foreach($locaties as $locatie) {
        			$list .= $modx->getChunk($rowTpl, array(
        				'naam' => $bedrijf->naam,
        				'plaats' => $locatie->plaats,
        				'telefoon' => $locatie->telefoon,
        				'fax' => $locatie->fax,
        				'website' => $bedrijf->website,
        				'email' => $bedrijf->email,
        			));
        		}
        	}
        }
        


        Is there a easier way to accomplish this?

        Thanks!

        Rogier
          • 25586
          • 105 Posts
          Anyone?