We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11975
    • 2,542 Posts
    Hi,

    I’m trying to insert TV values in @SELECT.

    My first TV:test
    input values : @SELECT name, id from ma_table1

    My second TV:test2 the values depends on the choice made in TV test

    input values : @SELECT name, id from ma_table2 WHERE id= [*TVtest*]

    is that possible??
    Till now MODx send back sql error contaning the [*TVtest*] (the value is not affected)

      Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
      • 11975
      • 2,542 Posts
      Some news,

      here is the code to get values for second TV according to selected value in first TV

      @EVAL $docID = $modx->getDocumentIdentifier('id');
      $templateTest = $modx->getTemplateVar('templateTest','*', $docID);
      if(strlen($templateTest['value'])>0){
      $sql= "SELECT name, id FROM modx_site_tmplvars LEFT JOIN modx_site_tmplvar_templates ON templateid=tmplvarid WHERE templateid=".$templateTest['value'];
      $rs = $modx->db->query($sql);
      while($myvalues = $modx->db->getRow($rs)) {
      $value .= $myvalues['name']."==".$myvalues['id']."||";
      }
      return substr($value,0,-2);
      }
      


      The code works fine as a snippet but send me back an error when pasted in input values

      Parse error: parse error, unexpected T_IS_EQUAL in /Users/fredm/Sites/moretto/manager/includes/tmplvars.commands.inc.php(51) : eval()’d code on line 1

      :-)

      EDIT: after some investigations the error comes from this part of the code

      $value .= $myvalues['name']."==".$myvalues['id']."||";


      If I remove the dot before "=" here --> "$value .= ", the error disappears.

      isn’t that odd !!!!

      EDIT2: the variable has to be affected first with $value="";

      the working code:
      @EVAL $docID = $modx->getDocumentIdentifier('id');
      $templateTest = $modx->getTemplateVar('templateTest','*', $docID);
      if(strlen($templateTest['value'])>0){
      $sql= "SELECT name, id FROM modx_site_tmplvar_templates LEFT JOIN modx_site_tmplvars ON tmplvarid=id WHERE templateid=".$templateTest['value']
      $rs = $modx->db->query($sql);
      $value="";
      while($myvalues = $modx->db->getRow($rs)) {
      $value .= $myvalues['name']."==".$myvalues['id']."||";
      }
      return substr($value,0,-2);
      }
      



        Made with MODx : [url=http://www.copadel.com]copadel, fruits et l