We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22102
    • 1 Posts
    Hi, i’m new in this world of modx and i’m trying to do something like this but i can’t find how to do it.

    Does anyone know if it is possible to do this in modx?

    $q = "SELECT username,userlevel "
    ."FROM ".TBL_USERS." WHERE userlevel=2 ORDER BY userlevel DESC,username";
    $result = $database->query($q);
    /* Error occurred, return given name by default */
    $num_rows = mysql_numrows($result);
    if(!$result || ($num_rows < 0)){
    echo "Error displaying info";
    return;
    }
    if($num_rows == 0){
    echo "Database table empty";
    return;
    }

    echo "<select name=\"to\">";
    for($i=0; $i<$num_rows; $i++){
    $uname = mysql_result($result,$i,"username");
    echo "<option size=\"30\" value=\"$uname\">$uname</option>";

    }
    echo "</select>";


    I’ve been reading about snippets and chunks, but i usually mix php and html, and i really don’t know how to fix this.

    Can you help me?
    Thanks!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Basically snippets [[SnippetName]] replace <?php ... ?> tags.

      http://www.sottwell.com/how-snippets-work.html

      Chunks are HTML; they can contain MODx snippet, chunk and TV tags. They are useful for encapsulating discrete blocks of content, such as sidebar blocks, isolating complex snippet tags (with lots of parameters) or for containing blocks of common content, such as page headers and footers, that will be used across an entire site with multiple templates.

      http://www.sottwell.com/how-templates-work.html

      It looks like you want to generate a select drop-down of recipients for email. Would these be manager users, or web users? You’ll want to query the relevant user_attributes table to get email addresses, joined with the relevant user_groups table to specify the group you want to target. MODx uses the concept of user groups rather than levels.

      Manager users are also assigned a "role". User/resource groups determine what resources and elements a manager user can access, while roles determine what they can do with them. Web user/resource groups determine what resources a web user can access.

      User groups (web or manager) are connected to resource groups, then users are assigned to the desired user group(s) and resources are assigned to the corresponding resource group(s).

        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
        • 32699 ☆ A M B ☆
        • 427 Posts
        Send the output of the snippet to a placeholder.

        The snippet will get ran first, and the placeholder populated before the page is finally parsed.

        You should NEVER mix php code with html. MODx makes it too easy to get chunks, use them as templates, and then spit out the resulting output.

        http://svn.modxcms.com/docs/display/revolution/MODx+PHP+Coding+Standards These are for revolution, but I do not believe they changed from evo.
          Get your copy of MODX Revolution Building the Web Your Way http://www.sanitypress.com/books/modx-revolution-building-the-web-your-way.html

          Check out my MODX || xPDO resources here: http://www.shawnwilkerson.com