-
- 25 Posts
After doing a lot of search I still dont get how to in the easiest way do a select statement on modx database tables from a snippet. I found a lot of xPDO. I didnt get it to work. Is it usefull here?
The statement I want to do in a snippet is:
"SELECT contentid, value FROM modx_site_tmplvar_contentvalues WHERE tmplvarid = XX"
Happy for all the help I can get.
-
- 24,544 Posts
xPDO would be *really* useful here. I'm not sure, but I think this is what you want:
<?php
/* Get all TemplateVarResource objects where the TV ID is 12 */
$tvrs = $modx->getCollection('modTemplateVarResource', array('templvarid' => '12'));
if (empty($tvrs)) {
return 'No TVRs found';
}
$output = "";
/* output the resource ID and Value for each one */
foreach ($tvrs as $tvr) {
$output .= '<br />Resource ID: ' . $tvr->get('contentid');
$output .= ' ---- Value: ' . $tvr->get('value');
}
return $output;
-
- 24,544 Posts
xPDO would be *really* useful here. I'm not sure, but I think this is what you want:
<?php
/* Get all TemplateVarResource objects where the TV ID is 12 */
$tvrs = $modx->getCollection('modTemplateVarResource', array('templvarid' => '12'));
if (empty($tvrs)) {
return 'No TVRs found';
}
$output = "";
/* output the resource ID and Value for each one */
foreach ($tvrs as $tvr) {
$output .= '<br />Resource ID: ' . $tvr->get('contentid');
$output .= ' ---- Value: ' . $tvr->get('value');
}
return $output;
-
- 24,544 Posts
Looks good. BTW, the select() is kind of overkill because the object only has three fields (other than the id) and you're getting almost all of them -- that's why I left it out, and since you're searching by tmplvarid, you may need to select it too, I'm not sure.
[ed. note: BobRay last edited this post 12 years, 5 months ago.]
-
- 24,544 Posts
No, I'd leave out the select line entirely. I think it will save you a tiny bit of memory, but cost you speed. I could be wrong.
-
- 24,544 Posts
No, I'd leave out the select line entirely. I think it will save you a tiny bit of memory, but cost you speed. I could be wrong.
-
- 25 Posts
Ok, understand. Thank you again for your help.