We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26693
    • 23 Posts
    Hey all,
    I’m trying to get some info to display from web_user_attributes once a user is logged in and on a certain page, this is info that they have written into the DB on signup (street address, company, fullname), having modified the web-signup snippet to include the two new fields, im now struggling to get it out again. What im using is a small snippet containing a modified version of what i found here. http://modxcms.com/dbapi-select.html and it looks a little like this
    <?php
    $userId = $modx->getLoginUserID();
    
    $table = $modx->getFullTableName("web_user_attributes");
    
    $info= $modx->db->select("fullname, streetaddress, country", $table, "internalKey = $userId" , "", "");
    
    return $info;
    ?>


    From what i can tell that should be pulling those three fields from that table and showing me the ones that belong to the current user (internalkey = userid), but it isnt, it returns "Resource id #19" or sometimes 13 or 14 or 15, I cant understand why its doing that. I am fairly poor when it comes to php and mysql and after a few hours of twiddling around with this I’ve run out of ideas on what to try next, can anyone lend a hand?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Your $info variable is a simple resource, you’ll need to extract the values just as you would from any mysql select statement. Try renaming $info to $results, then you’ll better be able to wrap your mind around the idea.

      <?php
      $userId = $modx->getLoginUserID();
      $table = $modx->getFullTableName("web_user_attributes");
      // make the SELECT query
      $results= $modx->db->select("fullname, streetaddress, country", $table, "internalKey = $userId" , "", "");
      // extract the results as an array
      $info=$modx->db->getRow($results);
      // display the results
      $output = "Name: ".$info['fullname'] ."<br />Address: ".$info['streetaddress']."<br />Country: ".$info['country']
      
      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
        • 26693
        • 23 Posts
        Hey Susan,
        Thanks very much for that looking much better than mine, love the comments to explain what is happening! Its not actually displaying anything on the page however (page loads just without the info on) and writes this to my error log
        [Mon Apr 09 10:46:56 2007] [error] [client 203.117.231.137] PHP Parse error:  syntax error, unexpected T_RETURN in /manager/includes/document.parser.class.inc.php(748) : eval()'d code on line 13

        Is this a problem with that file in particular, probably should have mentioned im using 0.9.6RC2, or is there something else going wrong that i havn’t noticed?
          • 7455
          • 2,204 Posts
          You could also grab it from the users session no need to go to the db to get all the info of the logged in user

          place this in a snippet and call it on your page to see what you can use.

          var_dump($_SESSION);

          Dimmy
            follow me on twitter: @dimmy01