MySQL query to get latest threads

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smartrconsults
    Member
    • Apr 2011
    • 44
    • 4.0.x

    [CMS] MySQL query to get latest threads

    Can anyone please give me the start point for the PHP code for a query that returns the latest threads from a given forum or forum group? I can't seem to find much in the documentation on this. I know PHP/MySQL so if I had a template to start from I'd be able to get it in no time.

    Thanks.
  • Andy
    Senior Member
    • Jan 2002
    • 5886
    • 4.1.x

    #2
    Here is a query I use for displaying a custom forumdisplay. Replace $f with the correct forumid number.

    $sql = "
    SELECT threadid, title, postusername, lastpostid, replycount
    FROM thread
    WHERE forumid='$f'
    AND visible='1'
    ORDER BY lastpost DESC
    LIMIT 50;

    Comment

    • maha191
      Member
      • Jan 2006
      • 39
      • 4.2.x

      #3
      hi andy

      by code

      PHP Code:
      <?php 

      chdir
      (public_html/forums); 
      require_once(
      './global.php'); 

      $threads $db->query_read(
      SELECT title FROM " 
      TABLE_PREFIX "thread 
      ORDER by dateline DESC 
      LIMIT 0,5 
      "
      ); 
      while (
      $thread $db->fetch_array($threads)) 

      echo 
      $thread['title'] . "<br />"

      ?>
      I want to have a link with

      thank you
      Thailand Vbulletin |Thailand country radio

      Comment

      • Trevor Hannant
        vBulletin Support
        • Aug 2002
        • 24359
        • 5.7.X

        #4
        For custom coding, please post at our customisation site, www.vbulletin.org
        Vote for:

        - Admin Settable Paid Subscription Reminder Timeframe (vB6)
        - Add Admin ability to auto-subscribe users to specific channel(s) (vB6)

        Comment

        • RichieBoy67
          Senior Member
          • Mar 2004
          • 205

          #5
          How can the amount of preview text be increased?

          Comment

          • Hartmut
            Senior Member
            • Nov 2007
            • 2870
            • 4.2.x

            #6
            PHP Code:
            $threads $db->query_read("
            SELECT IF(LENGTH(`title`) > 200, CONCAT(LEFT(`title`, 150), '...'), `title`) AS teaser
            FROM " 
            TABLE_PREFIX "thread 
            ORDER by dateline.teaser DESC 
            LIMIT 0,5 
            "
            ); 
            Everything above 200 characters will get shortend to 150 then plus a '...' will be added.
            No private support, only PM me when I ask for it. Support in the forums only.

            Comment

            • RichieBoy67
              Senior Member
              • Mar 2004
              • 205

              #7
              Thank you so much Hartmut!! I will give this a shot. I have been racking my brain on this.. Thank you

              I am trying to create a recent threads or posts center widget for the cms. I want to show much of the posts though and not just the basics as the current widgets do.

              Comment

              widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
              Working...