We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28376
    • 222 Posts
    Using the following modx API

    $modx->db->select

    how do i select from two tables. Lets say table one is called tbl1 and table two is called tbl2. Right now I can only select from tbl1.

    $table_prefix="tbl1";
    $username="ghost";
    $password="!@#$%^&*(";
    
       $res = $modx->db->select("id", $table_prefix."_web_users", 
          "username='$username' AND password='".$password."'");
    
    

      • 4172
      • 5,888 Posts
      If you need joins over more tables use $modx->db->query

      $tbl1=$modx->getFullTablename('web_users');
      $tbl2=$modx->getFullTablename('web_user_attributes');
              $sql = "SELECT wu.*, wua.fullname
                      FROM $tbl1 wu
                      INNER JOIN $tbl2 wua ON wua.internalkey=wu.id
                      WHERE "username='$username' AND password='".$password."'";
      
              $res = $modx->db->query($sql);
              $rows = $modx->db->makeArray($res);

        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!