We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26182
    • 164 Posts
    Hi,

    I am attempting to show the posts from one web user. However, I am getting this error:

    « MODx Parse Error »
    MODx encountered the following error while attempting to parse the requested resource:
    « Execution of a query to the database failed - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' longtitle, pub_date ORDER BY pub_date DESC LIMIT 10' at line 1 »
          SQL: SELECT * FROM `modx`.modx_site_content WHERE pagetitle, longtitle, pub_date ORDER BY pub_date DESC LIMIT 10;
          [Copy SQL to ClipBoard]
     
    Parser timing
      MySQL: 	0.0288 s	(15 Requests)
      PHP: 	0.0485 s	 
      Total: 	0.0774 s	 


    I wrote this snippet to try and show one post from the user:

    <?php
    //Author: Sarah
    //Date: 14-03-2007
    
    //This snippet displays the posts made by the user who is currently logged in.
    
    # set page to redirect to if user is not logged in, site_start by default
    if(!isset($_SESSION['webInternalKey']) || empty($_SESSION['webInternalKey'])) {
      $logout = isset($logout) ? $logout : $modx->config['site_start'];
      $modx->sendRedirect($modx->makeUrl($logout));
    }
    
    //Get user login name and store it in variable userLogin
    $userLogin = $modx->getLoginUserID();
    
    //Find the correct entries in the database that correspond to posts made by this user
    //Select the modx table where the posts are stored
    $tbl = $modx->getFullTableName('site_content');
    
    $tempUserPosts = $modx->db->select("*", $tbl, "pagetitle, longtitle, pub_date ", "pub_date DESC", "10");
    
    //return $userPosts;
    ?>


    Any help anyone could offer would be greatly appreciated.

    Thankyou.

    Sarah wink
      • 11975
      • 2,542 Posts
      Hi ,

      you could try with

      
      $tempUserPosts = $modx->db->select("*", $tbl, "createdby=".$userLogin, "pub_date DESC", "10");
      
      


      :-)
        Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
        • 26182
        • 164 Posts
        thanks for that. at least i am getting somethign to work with now smiley

        sarah
          • 18397
          • 3,250 Posts
          Or you could use Ditto and add &filter=`createdby,-WEBUSERID,1` note that the webuser ID must be negative for this to work as createdby values are stored negative for webusers.
            • 26182
            • 164 Posts
            thanks for your help. managed to get it working smiley