Summary
I need to retrieve the value of two template variables along with select Resource fields (id, pagetitle) from the site_content table.
Details
To retrieve the values I have an SQL query however the result includes extra rows. This happens because the Resources involved have values set other template variables and I don’t know how to exclude these in the query.
SELECT DISTINCT does not work because the values returned for tv_videoID and tv_videoValue do not match.
I tried the native method (I don’t know the correct terminology) $c = $modx->newQuery(‘modResource’) but struggled to build the query, most likely as I’m doing it incorrectly.
The Template Variables are
#10 video-src
#11 video-poster
The SQL query is
SELECT content.id,
content.pagetitle,
tvvalues.value as tv_videoID,
(SELECT value FROM rap2_site_tmplvar_contentvalues
WHERE rap2_site_tmplvar_contentvalues.contentid = tvvalues.value AND rap2_site_tmplvar_contentvalues.tmplvarid = 10) as tv_videoValue,
(SELECT value FROM rap2_site_tmplvar_contentvalues
WHERE rap2_site_tmplvar_contentvalues.contentid = tvvalues.value AND rap2_site_tmplvar_contentvalues.tmplvarid = 11) as tv_videoPoster
FROM rap2_site_content as content
LEFT JOIN rap2_site_tmplvar_contentvalues as tvvalues
ON content.id = tvvalues.contentid
WHERE content.parent = 65
AND class_key != 'CollectionContainer'
AND content.published = 1
AND content.hidemenu = 0;
The result is
In this example I want just the first row. In the second row the tv_videoID value is from the same Resource as row 1 but for Template Variable #9 which isn’t needed.
Can anyone help me rewrite the SQL query or suggest an alternative approach?
Thanks