We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30741
    • 65 Posts
    I am trying to get a php Code to run but for some reason it isn’t displaying anything but the bottom section of the script. When it isn’t part of Modx it show up fine. So what am I doing wrong?
         <?php 
    ##########################################################################
    // RECENT TOPICS by LBmtb
    // Version 1.03
    // [email protected] OR aim: LBmtb
    //
    // Do not remove copyright unless you donate $5 via paypal
    // to the above email address, thanks
    // CUSTOMIZED from a www.phase1media.com script found here:
    // http://www.vbulletin.org/forum/showpost.php?p=589067&postcount=7
    ##########################################################################
    
    ## CUSTOMIZE THE FOLLOWING    ##############################################
    
    // DATABASE & URL SETTINGS
    $db_host = "HOST HERE"; // Change this if your MySQL database host is different.
    $db_name = "DB Name"; // Change this to the name of your database.
    $db_user = "USER"; // Change this to your database username.
    $db_pw = "PW HERE"; // Change this to your database password.
    $db_prefix = "vbb37x_"; // Change to your tables' prefix. Usually vb_
    $forum_url = "Forum HERE "; // Change this to reflect to your forum's URL.
    
    // APEARANCE OPTIONS
    $seperator = "@"; // this goes between last poster and date
    $limit = "15"; // Number of posts displayed
    $post_date_format = "2"; // leave as 1 for "12/18/06 05:26 PM" or change to 2 for "05:26 PM"
    
    // use one or the other, not both. if left blank the script will return threads from any forum
    $fid_raw = ""; // ONLY include threads from these forums. seperate each ID with a comma
    $fidx_raw = "62, 72, 73, 51"; // Exclude threads from these forum. seperate each ID with a comma
    
    // CSS CLASSES    
    $recent_topics = "vb_topics"; // you can use CSS to adjust the presentation of the list 
    $recent_poster = "vb_last_post";  // you can use CSS to adjust the presentation the last poster and date
    
    ## NO NEED TO TOUCH ANYTHING BELOW    #####################################
    #############################################################################
    
    if (!($recent_topics_connection = mysql_connect("$db_host", "$db_user", "$db_pw")))
    die ("could not connect"); 
    if (!(mysql_select_db("$db_name", $recent_topics_connection)))
    mysql_error(); 
    echo "<ul class=\"$recent_topics\">\n";
    $fid_array = explode (',', $fid_raw);
    if ($fid_raw)  {
        $fid_final .= "AND (";
        foreach( $fid_array as $key => $value){
            if ($key == 0) { $fid_final .= "t.forumid=".$value; }
            else { $fid_final .= " OR t.forumid=".$value; }
        }
        $fid_final .= ")";
    }
    $fidx_array = explode (',', $fidx_raw);
    if ($fidx_raw)  {
        $fidx_final .= "AND NOT (";
        foreach( $fidx_array as $key => $value){
            if ($key == 0) { $fidx_final .= "t.forumid=".$value; }
            else { $fidx_final .= " OR t.forumid=".$value; }
        }
        $fidx_final .= ")";
    }
    $thread_sql = mysql_query("SELECT SQL_CACHE t.threadid,t.title,t.lastpost,t.lastposter,t.forumid,substring(p.pagetext,1,90) as post_text
    	FROM ".$GLOBALS['db_prefix']."thread t
    	INNER JOIN ".$GLOBALS['db_prefix']."post p
    	ON t.firstpostid = p.postid
    	WHERE t.visible=1 
    	AND t.open=1 $fidi_final $fidx_final 
    	ORDER BY t.lastpost desc 
    	LIMIT $limit");
    while($thread_get=@mysql_fetch_array($thread_sql))
    {
        $lastpost = $thread_get['lastpost'];
        $poster = $thread_get['lastposter'];
        $tid = $thread_get['threadid'];
    $text = $thread_get['post_text'];
        if ($post_date_format == "1") { $date2 = date ("m/d/y h:i A" ,$lastpost); }
        elseif ($post_date_format == "2") { $date2 = date ("h:i A" ,$lastpost); }
        else { $date2 = date ("m/d/y h:i A" ,$lastpost); }
    	    echo "<li><a href=\"$forum_url/showthread.php?t=$tid\" title=\"".$text."\">$thread_get[title]</a> <span class=\"$recent_poster\">($poster $seperator $date2)</span></li>\n";
    }
    echo "</ul>\n<div style=\"font-size: .9em; text-align: center;\">recent topics by <a href=\"http://forum.fourthirdsphoto.com/search.php?do=getnew\"><acronym title=\"fourthirdsphoto\">fourthirdsphoto.com</acronym></a></div>";
    mysql_close($recent_topics_connection);
    ?>
    
    


    Am I missing a call can someone give some suggestions?

    I should add I have tried the call with a [!snippet!]
    Thanks
    Tony
      • 3749
      • 24,544 Posts

      Try this (untested):

      <?php
      $output = "";
      
      /* your code */
      
      $output = '<ul class="' . $recent_topics . '"' . "\>\n";
      
      /* your code */
      
      else { $date2 = date ("m/d/y h:i A" ,$lastpost); }
      	    $output .= '<li><a href="' . $forum_url . '/showthread.php?t=' . $tid . '" title=""' .$text. '">' . $thread_get[title] . '</a> <span class="'. $recent_poster . '">(' . $poster . $seperator . $date2 . ')</span></li>' . "\n";
      }
      $output .= "</ul>\n" . '<div style="font-size: .9em; text-align: center;">recent topics by <a href=\"http://forum.fourthirdsphoto.com/search.php?do=getnew"><acronym title="fourthirdsphoto">fourthirdsphoto.com</acronym></a></div>';
      
      return $output;
      ?>
        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
        • 30741
        • 65 Posts
        That looks closer to what I was thinking, but really it still isn’t quite correct -
        [06-Sep-2009 00:03:34] PHP Warning:  fopen(/Users/tonywork/Sites/poole/assets/templates/manager/welcome.php) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory in /Users/tonywork/Sites/poole/manager/actions/welcome.static.php on line 194
        [06-Sep-2009 00:03:34] PHP Warning:  filesize() [<a href='function.filesize'>function.filesize</a>]: stat failed for /Users/tonywork/Sites/poole/assets/templates/manager/welcome.php in /Users/tonywork/Sites/poole/manager/actions/welcome.static.php on line 195
        [06-Sep-2009 00:03:34] PHP Warning:  fread(): supplied argument is not a valid stream resource in /Users/tonywork/Sites/poole/manager/actions/welcome.static.php on line 195
        [06-Sep-2009 00:03:34] PHP Warning:  fclose(): supplied argument is not a valid stream resource in /Users/tonywork/Sites/poole/manager/actions/welcome.static.php on line 196
        [22-Sep-2009 00:03:34] PHP Parse error:  syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /Users/tonywork/Sites/poole/manager/includes/document.parser.class.inc.php(770) : eval()'d code on line 2

        Does the error log help?
          • 3749
          • 24,544 Posts
          Check the value of $forum_url (just a guess). It has to be set the actual URL of your forum.

          You need to fill in the correct values at the top where it says "Customize These."

            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
            • 30741
            • 65 Posts
            Thanks Bob,
            For the reply, I think that it should work, but not. I do have the correct DB values and even the full URL for my forum, but I seem to just have something slightly wrong.
            I need to try to spend an hour or so and focus on this, because I think your call is correct but I think I just am putting stuff in the wrong spot.
              • 3749
              • 24,544 Posts
              If you have Friendly URLs on, I would turn them off and rename .htaccess until you get the forum working.
                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
                • 30741
                • 65 Posts
                Thanks Bob,
                I just instead went with a JavaScript file, to get it working.
                I am sure if I were better at PHP it would have been a simple fix. But it should be good to go.

                Thanks for your help. Maybe next week, when I am not in the midst of a transition I will try it again.