We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    If you're in a plugin, you don't want $modx->user, you want $user.
      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
      • 35756
      • 166 Posts
      OK, i didn't get it to run with editing the given code of the ExtUserUpdateProfile-snippet.

      But I found another way to get this done by using this:

      if(mysql_num_rows(mysql_query("SELECT ext_user_data WHERE userid = '$id'"))){
      // Code inside if block if userid is already there
      $sql ="update ext_user_data set `vorname` = '$vorname', `nachname` = '$nachname' where id='$id'";
      $stmt = $modx->prepare($sql);
      $stmt->execute();
      } 
      else {
      $sql ="insert into ext_user_data (id,userdata_id,vorname,nachname) values('$id','$id','$vorname','$nachname')";
      $stmt = $modx->prepare($sql);
      $stmt->execute();
      }
        • 3749
        • 24,544 Posts
        Looks good. That should be faster anyway.
          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
          • 35756
          • 166 Posts
          damn it, I got stuck again...

          Now that I got rid of those "normal" profile extended-fields and only use the DB-table-values, some of the placeholders I created don't get created now anymore.

          Before I used this to get those "Normal" extended-fields:

          if ($profile) {
              $fields = $profile->get('extended');
          }
          if ( $fields['jobphone'] != '' OR $fields['jobemail'] != '' ) {
          $modx->setPlaceholder('job-kontakt', '1');
          }


          This is used to insert some headlines if those fields are not empty.

          [[+job-kontakt:is=`1`:then=`<h1>Business Contact</h1>`]]


          So now I tried this by using the DB-table-values like that:

          if(mysql_num_rows(mysql_query("SELECT ext_user_data WHERE userid = '$id' AND jobphone != '' "))){
          $modx->setPlaceholder('job-kontakt', '1');
          echo '123';
          } 


          But without success...any hint on that again anyone?
            • 35756
            • 166 Posts
            i think i got it, but in a bad manner:

            $job-kontakt = "SELECT * FROM `ext_user_data` WHERE `id` = '$userId' AND `jobphone` != '' AND `jobphone` != 'NULL' ";
            $query1 = $modx->query($job-kontakt);
            $rows1 = array();
            if ($query1) {
                // loop through the result set and inspect one row at a time
                while ($row = $query1->fetch(PDO::FETCH_ASSOC)) {
                    array_push($rows1, $row);
            $modx->setPlaceholder('job-kontakt', '1');
            
                }
            }
            
            $job-kontakt = "SELECT * FROM `ext_user_data` WHERE `id` = '$userId' AND `jobemail` != '' AND `jobemail` != 'NULL' ";
            $query2 = $modx->query($job-kontakt);
            $rows2 = array();
            if ($query2) {
                // loop through the result set and inspect one row at a time
                while ($row = $query2->fetch(PDO::FETCH_ASSOC)) {
                    array_push($rows2, $row);
            $modx->setPlaceholder('job-kontakt', '1');
            
                }
            }


            I wasn't able to combine that, then it didn't work correct.
              • 3749
              • 24,544 Posts
              You might try this to get it in a single query:

              SELECT * FROM `ext_user_data` WHERE `id` = '$userId' AND 
              (
                  (`jobphone` != '' AND `jobphone` != 'NULL')
                OR 
                  (`jobemail` != '' AND `jobemail` != 'NULL')
              ) ";
                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