We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27728
    • 12 Posts
    I’m using a modified version of loopDbChunk to pull events from an external database.
    Works perfect however I need a way to use the logged in users email in the WHERE clause.

    Is there a workaround to make this happen?
    I was hoping to sub the email with placeholder like below.
    <?php
    include("assets/snippets/eventlister/config.php");
    
    $query = "
    SELECT *
    FROM subscriptions
    WHERE email = '[+user.email+]'
    ";
    
    $paramra = array(
      'hostvar' =>$dbhost, 
      'uservar' => $dbuser, 
      'passvar' => $dbpass, 
      'databasevar'=> $dbname, 
      'sql' =>$query,
      'chunkName' =>'youreventsformat',
      'perPage' => '',
      'orderby' => '',
      'missingValTxt' => '--');
    
    return $modx->runSnippet('loopDBChunk' , $paramra);
    ?>
    


    could this maybe be done with a call to the mod database for the email using the internalKey or getLoginUser or something?
    Thanks for any help.

      • 4310
      • 2,310 Posts
      This might do it :
      $_SESSION['webEmail']
        • 27728
        • 12 Posts
        Man, so close I think.
        Just not sure if my syntax is correct.

        would it be:
        WHERE email = $_SESSION['webEmail']
        
         or
        
        WHERE email = '$_SESSION['webEmail']'
        
        I guess I'm just too clueless.
        
          • 27728
          • 12 Posts
          Closer.

          I tried using:
          <?php
          include("assets/snippets/eventlister/config.php");
          
          $email = $_SESSION['webEmail'];
          
          $query = "
          SELECT *
          FROM subscriptions
          WHERE email = '$email'
          ";
          
          $paramra = array(
            'hostvar' =>$dbhost, 
            'uservar' => $dbuser, 
            'passvar' => $dbpass, 
            'databasevar'=> $dbname, 
            'sql' =>$query,
            'chunkName' =>'youreventsformat',
            'perPage' => '',
            'orderby' => '',
            'missingValTxt' => '--');
          
          return $modx->runSnippet('loopDBChunk' , $paramra);
          ?>
          


          and that sort of worked. It is returning data, but the data is not the same as if I just put the email in the WHERE
            • 4310
            • 2,310 Posts
            Untested but maybe try :
            <?php
            include("assets/snippets/eventlister/config.php");
            
            $email = $_SESSION['webEmail'];
            
            $query = "
            SELECT *
            FROM subscriptions
            WHERE email = \'{$email}\'
            ";
            
            $paramra = array(
              'hostvar' =>$dbhost, 
              'uservar' => $dbuser, 
              'passvar' => $dbpass, 
              'databasevar'=> $dbname, 
              'sql' =>$query,
              'chunkName' =>'youreventsformat',
              'perPage' => '',
              'orderby' => '',
              'missingValTxt' => '--');
            
            return $modx->runSnippet('loopDBChunk' , $paramra);
            ?>
            
              • 27728
              • 12 Posts
              Thanks for the effort, but that tosses out a parse error.
              so, so , so close.

              I just cant figure out why it works, but data is bad.
              duplicates some, and they are cut down to like 50 characters.
                • 27728
                • 12 Posts
                Not sure what I did, but I got it working with:
                <?php
                include("assets/snippets/eventlister/config.php");
                
                $email = $_SESSION['webEmail'];
                
                $query = "
                SELECT *
                FROM subscriptions
                WHERE email = '$email'
                ";
                
                $paramra = array(
                  'hostvar' =>$dbhost, 
                  'uservar' => $dbuser, 
                  'passvar' => $dbpass, 
                  'databasevar'=> $dbname, 
                  'sql' =>$query,
                  'chunkName' =>'youreventsformat',
                  'perPage' => '',
                  'orderby' => '',
                  'missingValTxt' => '#');
                
                return $modx->runSnippet('loopDBChunk' , $paramra);
                ?>
                


                Big thanks... can I buy you a beer or coffee or something?
                  • 4310
                  • 2,310 Posts
                  smiley Thanks is all that’s required