Bingo Reply #1, 4 months, 2 weeks ago
I am completely new to xpdo so I'm sorry if it's a stupid question.
I try to capture only one value in my database. I have solved it using the code below, but realizes that it must be possible to solve without foreach. But how?
The value in alias is always unique and I just want the id back.
I try to capture only one value in my database. I have solved it using the code below, but realizes that it must be possible to solve without foreach. But how?
The value in alias is always unique and I just want the id back.
$output = '';
$query = $modx->newQuery('Product');
$query->select($modx->getSelectColumns('Product','Product','',array('id')));
$query->where(array(
'alias' => 'PRODUCT-NAME',
));
$products = $modx->getCollection('Product',$query);
foreach ($products as $product) {
$output = $product->get('id');
}
return $output;