We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29806
    • 8 Posts
    This user list is very messy code but it works I will clean it and make it more MODx style when I have time.

    Snippet named "Userlist"
    include_once "assets/snippets/Userlist/userlist.inc.php";


    userlist.inc.php
    <?
    //setting:
    $pgPageLength = 10;  // How many users per page??
    
    /*===== EDIT WITH CARE BELOW =====*/
    $gotoPage = $_GET["gotoPage"];
    
    $theQuery = $modx->db->select("*", $modx->getFullTableName('web_users'), "", $userId, "");
    $theRowsAmount = $modx->db->getRecordCount($theQuery);
    
    $pgTotalPages = intval($theRowsAmount/$pgPageLength);
    //echo $pgTotalPages; //debug
    if ($theRowsAmount%$pgPageLength) {
    	$pgTotalPages++;
    }
    
    if ($gotoPage != ""){
        if ($gotoPage == "1"){
    		$pgStartPoint = 0;
        }else{
    		$pgStartPoint = ($pgPageLength * $gotoPage) - 10;
        }
    }else{
    	$pgStartPoint = 0;
    }
    $getDetails = $modx->db->query("SELECT * FROM modx_web_users ORDER BY id ASC LIMIT $pgStartPoint, $pgPageLength");
    //$getDetails = $modx->db->select("*", $modx->getFullTableName('web_users'), "", $UserId, $pgPageLength);
    // I am not sure why the select function will not work any hints appreciated
    if(!($getDetails)) { 
    	print "Unable to access database for modx_web_users!";
    }
    ?>
    <table id="main table" width="500" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td id="usrtop"><?
    $ShownPage = $gotoPage;
    if ($ShownPage != ""){
    }else{
    $ShownPage = 1;
    }
    if ($ShownPage == 1){
    }else{
    $PrevPage = $ShownPage - 1;
    ?>
    <a href="index.php?id=11&gotoPage=<? echo $PrevPage; ?>">Prev</a>
    <?
    }
    
    if ($pgTotalPages >= 11){
        $pgFirstLoads = $ShownPage - 5;
        $pgLastLoads = $ShownPage + 4;
        
            if ($pgLastLoads >= $pgTotalPages){
            $pgLastLoads = $pgTotalPages;
            $pgLastDots = "";
            }else{
            $pgLastDots = " | ... | <a href=\"index.php?id=11&gotoPage=$pgTotalPages\">Last</a>";
            }
            
            if ($pgFirstLoads <= 1){
            $pgFirstLoads = 0;
            $pgFirstDots = "";
            }else{
            $pgFirstDots = " | <a href=\"index.php?id=11&gotoPage=1\">First</a> | ...";
            }
            echo $pgFirstDots;
                for($i = $pgFirstLoads; $i < $pgLastLoads; $i++) { 
                $currPage = $i + 1;
                if ($currPage != $ShownPage){    
                echo " | <a href=\"index.php?id=11&gotoPage=$currPage\">$currPage</a>"; 
                }else{
                echo " | <strong>$currPage</strong>";
                }
                }
            echo $pgLastDots;
    }else{
        for($i = 0; $i < $pgTotalPages; $i++) { 
        $currPage = $i + 1;
            if ($currPage != $ShownPage){    
            echo " <a href=\"index.php?id=11&gotoPage=$currPage\">$currPage</a>"; 
            }else{
            echo " <strong>$currPage</strong>";
            }
        }
    }
    
    if ($ShownPage == $pgTotalPages){
    }else{
    $NextPage = $ShownPage + 1;
    ?>
     | <a href="index.php?id=11&gotoPage=<? echo $NextPage; ?>">Next</a>
    <?
    } 
    ?>
    </td>
      </tr>
      <tr>
        <td><table id="results" width="50%" border="0" cellspacing="0" cellpadding="0">
    		<tr>
            <td id="id">ID</td>
            <td id="uname">Username</td>
    	</tr>
    
    <?
    while ($row = $modx->db->getRow($getDetails)) {  
              $getUsername = $row['username'];
              $getId = $row['id'];
    
    ?>
    	<tr>
            <td id="id"><? echo $getId; ?></td>
            <td id="uname"><? echo $getUsername; ?></td>
    	</tr>
    <?
    }
    mysql_close();
    ?>
    
        </table></td>
      </tr>
      <tr>
        <td id="paging bottom here"><?
    $ShownPage = $gotoPage;
    if ($ShownPage != ""){
    }else{
    $ShownPage = 1;
    }
    if ($ShownPage == 1){
    }else{
    $PrevPage = $ShownPage - 1;
    ?>
    <a href="index.php?id=11&gotoPage=<? echo $PrevPage; ?>">Prev</a>
    <?
    }
    
    if ($pgTotalPages >= 11){
        $pgFirstLoads = $ShownPage - 5;
        $pgLastLoads = $ShownPage + 4;
        
            if ($pgLastLoads >= $pgTotalPages){
            $pgLastLoads = $pgTotalPages;
            $pgLastDots = "";
            }else{
            $pgLastDots = " | ... | <a href=\"index.php?id=11&gotoPage=$pgTotalPages\">Last</a>";
            }
            
            if ($pgFirstLoads <= 1){
            $pgFirstLoads = 0;
            $pgFirstDots = "";
            }else{
            $pgFirstDots = " | <a href=\"index.php?id=11&gotoPage=1\">First</a> | ...";
            }
            echo $pgFirstDots;
                for($i = $pgFirstLoads; $i < $pgLastLoads; $i++) { 
                $currPage = $i + 1;
                if ($currPage != $ShownPage){    
                echo " | <a href=\"index.php?id=11&gotoPage=$currPage\">$currPage</a>"; 
                }else{
                echo " | <strong>$currPage</strong>";
                }
                }
            echo $pgLastDots;
    }else{
        for($i = 0; $i < $pgTotalPages; $i++) { 
        $currPage = $i + 1;
            if ($currPage != $ShownPage){    
            echo " <a href=\"index.php?id=11&gotoPage=$currPage\">$currPage</a>"; 
            }else{
            echo " <strong>$currPage</strong>";
            }
        }
    }
    
    if ($ShownPage == $pgTotalPages){
    }else{
    $NextPage = $ShownPage + 1;
    echo " | <a href=\"index.php?id=11&gotoPage=".$NextPage."\">Next</a>";
    } 
    
    echo "</td>\n";
    echo "</tr>\n";
    echo "</table>";
      • 29806
      • 8 Posts
      Ok I would like to redo this with datagrid class but, I do not know how to use it. Does anyone have any snippets using it i can use as a guide?


      .....
      $modx->db->getHTMLGrid($row, $params);  //???
        • 18397
        • 3,250 Posts
        I do but it runs as a module.....

        If you still want it I can give you a peek.
          • 29806
          • 8 Posts
          I would appreciate that my email is [email protected]
            • 18397
            • 3,250 Posts
            Sent.