I’m beginning to understand how to create custom snippets in modx, and am really excited each time I figure out part of the API. But as always when learning, you get stuck somewhere...
I’m trying to create a snippet that executes the mySql query contained in the code below. It basically compares values across the whole document tree for several TVs (48,50,26), filters them, then returns the lowest ’price’ value from the results.
The filter values (28, 24) are static until I can get it working correctly. The query itself is valid SQL:
<?php
function getPrice() {
global $modx;
$output = '';
$result = $modx->db->query( '
SELECT t3.value
FROM `hlp_site_tmplvar_contentvalues` t
INNER JOIN (`hlp_site_tmplvar_contentvalues` t2,
`hlp_site_tmplvar_contentvalues` t3)
ON t.contentid = t2.contentid
AND t2.contentid = t3.contentid
AND t.tmplvarid = '48'
AND t2.tmplvarid = '50'
AND t3.tmplvarid = '26'
WHERE t.value >= '28' AND t2.value >= '24'
ORDER BY t3.value ASC
LIMIT 1
');
if( $modx->db->getRecordCount( $result ) >= 1 ) {
while( $row = $modx->db->getRowArray( $result ) ) {
$output .= 'Value: ' . $row['t3.value'];
}
}
else {
$output = 'No records to show' ;
}
return $output;
}
?>
Unfortunately I can’t get anything output. I’ve tried even with a basic sql query and I can’t get anything to pop out, so presumably the issue is with my php.
Is anyone able to help me out?
Cheers, Luke