We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36573
    • 173 Posts
    I'm attempting to use pdouser with the &where statement to filter them. A user must have "0000000000" and "Member" and any of the zip codes. What I show here is not working and I'm unable to find any docs on the &where statement.

    [[!pdoUsers?
    &tpl=`userListTpl`
    &where=`{"AND:modUserProfile.fax:=":"0000000000",
             "AND:modUserProfile.comment:=":"Member",
             "OR:modUserProfile.zip:=":"83206",
             "OR:modUserProfile.zip:=":"83209",
             "OR:modUserProfile.zip:=":"83201"}`
    &limit=`0`
    &useExtended=`1`]]
      Everything I know I learned on the internet. Saved me thousands in College tuition,
      • 3749
      • 24,544 Posts
      This might help: http://rtfm.modx.com/xpdo/2.x/class-reference/xpdoquery/xpdoquery.where

      If you have an editor that can run PHP, you can write it as an array, then do this to get the string to use in the &where property:

      echo json_encode($myArray);


      or in a MODX snippet:


      return $modx->toJSON($myArray);
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 44580
        • 189 Posts
        The zip code should use 'IN', and the first 'AND' is not needed.
        &where=`{"modUserProfile.fax:=":"0000000000",
                 "AND:modUserProfile.comment:=":"Member",
                 "AND:modUserProfile.zip:IN":array(83206,83209,83201)}`

        I'm not 100% sure on the actual syntax, but the above should get you on the way. The link Bob posted is the best documentation I can find, but it does not have many useful examples.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Once you get the list of zipcodes into an array, this code will display what you want:
              $c = $modx->newQuery('modUser');
              $c->leftJoin('modUserProfile','Profile');
           
              // add column names that u want to show
              $c->select(array(
                  'modUser.*',
                  'Profile.fullname',
                  'Profile.city',
                  'Profile.zip',
                  'Profile.email',
                  'Profile.phone',
              ));
              $c->where(array(
                  'Profile.fax:=' => '0000000000',
                  'AND:Profile.zip:IN' => $zipArray,
              ));
          
              $users = $modx->getCollection("modUser",$c);
              
              $output = '';
              
              // use a chunk tpl for formatting the output
              // all retrieved user and profile fields will be placeholders
              foreach($users as $user){
                  if($user->isMember('theGroup')) {
                      $userArray = $user->toArray();
                      $output .= $modx->getChunk('listTpl', $userArray);
                  }
              }
          
              return $output;
          }
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 36573
            • 173 Posts
            Quote from: sottwell at Nov 15, 2014, 11:21 AM
            Once you get the list of zipcodes into an array, this code will display what you want:
                $c = $modx->newQuery('modUser');
                $c->leftJoin('modUserProfile','Profile');
             
                // add column names that u want to show
                $c->select(array(
                    'modUser.*',
                    'Profile.fullname',
                    'Profile.city',
                    'Profile.zip',
                    'Profile.email',
                    'Profile.phone',
                ));
                $c->where(array(
                    'Profile.fax:=' => '0000000000',
                    'AND:Profile.zip:IN' => $zipArray,
                ));
            
                $users = $modx->getCollection("modUser",$c);
                
                $output = '';
                
                // use a chunk tpl for formatting the output
                // all retrieved user and profile fields will be placeholders
                foreach($users as $user){
                    if($user->isMember('theGroup')) {
                        $userArray = $user->toArray();
                        $output .= $modx->getChunk('listTpl', $userArray);
                    }
                }
            
                return $output;
            }

            Does this go in that other snippet findZip? I had to fiddle with it to keep the project moving forward.


              Everything I know I learned on the internet. Saved me thousands in College tuition,
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Yes. It's in place and working. I just need to know what you want to do.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 36573
                • 173 Posts
                If you look at snippet and index.php?id=20 you'll see what I need. But I can't get the snippet to filter the users at all. I'll also want different levels of information based on whether the user is logged in as a rider or not. I would imagine that would be a basic if statement. I won't mess with anymore if you can take it look at it.
                  Everything I know I learned on the internet. Saved me thousands in College tuition,
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  Should be working now. Just need to add some output modifiers to the tpl chunk to show the extra info to logged-in users.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 36573
                    • 173 Posts
                    Ha! I messed with that thing all afternoon trying to figure it out. Grrrrrrr! Thanks!

                    $c->select(array(
                            'modUser.*',
                            'Profile.fullname',
                            'Profile.city',
                            'Profile.zip',
                            'Profile.email',
                            'Profile.phone',
                        ));


                    In this section how do I pull from the extended fields?
                      Everything I know I learned on the internet. Saved me thousands in College tuition,
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      That's awkward. Perhaps use the Comments field instead?
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org