How do I change this:
UPDATE A.value = 'InTeam'
FROM `modx_site_tmplvar_contentvalues` AS A, `modx_site_tmplvar_contentvalues` AS B
WHERE A.`contentid` = B.`contentid` AND A.`tmplvarid`='27' AND B.`value`='Stevens' AND B.`tmplvarid` = '8'
using the MODx DBAPI, to this:
$modx->db->update("fields", "table_name", "where value");
TIA
Website: www.mercologia.com
MODX Revo Tutorials: www.modxperience.com
MODX Professional Partner
Yeah, I have read the new wiki and the old wiki and I have also used SELECT and UPDATE in
the normal way... my problem is with the tmpvar_contentvalues table where all the info is
in the Value field and so the need to use the same table as A.xxx and B.xxx.
This works fine in the TVs using the @ binding but I dont know with the DBAPI
The problem with your where is that for example...
’modx_site_tmplvar_contentvalues.`contentid` = modx_site_tmplvar_contentvalues.`contentid`
is comparing exactly the same value and then you ask for A.value in $rows_affected...
somehow we have to tell modx that we are using the same table as A.xxx and B.xxx...
maybe is as simple as just transcribing the names just as they appear in the phpmyadmin query
that works...
Website: www.mercologia.com
MODX Revo Tutorials: www.modxperience.com
MODX Professional Partner
I think in this case you have to use
$modx->db->query("UPDATE A.value = 'InTeam'
FROM `modx_site_tmplvar_contentvalues` AS A, `modx_site_tmplvar_contentvalues` AS B
WHERE A.`contentid` = B.`contentid` AND A.`tmplvarid`='27' AND B.`value`='Stevens' AND B.`tmplvarid` = '8'");
Thanks Bruno, yes, I was thinking the same this morning, clearer head...
I will try it and process with getRow or getValue and the like... thanks...
Website: www.mercologia.com
MODX Revo Tutorials: www.modxperience.com
MODX Professional Partner
Yes, I had the same reservation, FROM does not work in an UPDATE in MySQL and had
to test WHERE too.
So this works fine in phpmyadmin and should work in the $modx->db->query() function...
UPDATE `modx_site_tmplvar_contentvalues` AS A, `modx_site_tmplvar_contentvalues` AS B
SET A.`value` = '$flag'
WHERE A.`contentid` = B.`contentid` AND A.`tmplvarid`='27' AND B.`value`='$ivalue' AND B.`tmplvarid` = '8'
Website: www.mercologia.com
MODX Revo Tutorials: www.modxperience.com
MODX Professional Partner
-
☆ A M B ☆
- 2,475 Posts
Sorry, yes, I meant SET. Update queries don’t have FROM’s.