<a href="[[~27? &prodNum=`[[+name]]` &famCode=`[[+fam]]`]]">
$famId = $_GET['famCode'];
$families = $modx->getCollection('BbProducts',$famId);
foreach($families as $family) {
$imgName = $family->get('name');
$nwN = 'Name: ' . $imgName;
$imgLink = 'assets/media/jpgs/' . $imgName . '.jpg';
$fields = $family->toArray();
$output = $modx->getChunk('showProductFam', array_merge($fields, array('nwN'=>$nwN, 'imgLink'=>$imgLink)));
}<div> <img title="[[+name]]" src="[[+imgLink]]" alt="[[+name]]" /><br> [[+nwN]] </div>
This question has been answered by multiple community members. See the first response.
$families = $modx->getCollection('BbProducts', array('fam' => $famId));$families = $modx->getCollection('BbProducts', array('fam' => $famId));
https://rtfm.modx.com/xpdo/2.x/class-reference/xpdo/xpdo.getcollection
$families = $modx->getCollection('BbProducts',$famId);I'm looking for all the products that have the same family code.$families = $modx->getCollection('BbProducts',$famId);
What type of the second parameter? Which (SQL-)query you expect?
$families = $modx->getCollection('BbProducts', (int) $famId);$families = $modx->getCollection('BbProducts', array('fam' => (int) $famId));$output .= $modx->getChunk('showProductFam', $fields);$output = "";
Your code looks close to me.
This will work *if* the $famId variable contains the value of the primary key for that object. If that value is an integer, put (int) in front of it like this:
$families = $modx->getCollection('BbProducts', (int) $famId);
If it's not the primary key you'd have to use something like Yasya_popkin's code (replace 'fam' with the field name of the field holding that value, and again, it it's an integer field, but (int) in front of it):
$families = $modx->getCollection('BbProducts', array('fam' => (int) $famId));
You shouldn't need the array_merge() since $fields already holds the correct array, but you need to use .= rather than =, otherwise you'll only get the last one.
$output .= $modx->getChunk('showProductFam', $fields);
You should put this at the very top. It's good form and will prevent E_NOTICE errors:
$output = "";
$famId = $_GET['famCode'];
$families = $modx->getCollection('BbProducts', array('fam' => (int) $famId));
foreach($families as $family) {
$imgName = $family->get('name');
$nwN = 'Name: ' . $imgName;
$imgLink = 'assets/media/jpgs/' . $imgName . '.jpg';
$fields = $family->toArray();
$output .= $modx->getChunk('showProductFam', array_merge($fields, array('nwN'=>$nwN, 'imgLink'=>$imgLink)));
}
$fields = $family->toArray();
$imgName = $family->get('name');
$fields['nwN'] = 'Name: ' . $imgName;
$fields['imgLink'] = 'assets/media/jpgs/' . $imgName . '.jpg';
$output .= $modx->getChunk('showProductFam', $fields);$c = $modx->newQuery('BbProducts');
$c->where(array('fam' => (int) $famId));
$c->sortby('name', 'ASC');
$families = $modx->getCollection('BbProducts', $c);