Seite 1 von 1

Abfrage des neuesten Posts eines definierten Threats

Verfasst: 12.10.2013 19:19
von SIL_EL_MOT
Hallo, ich möchte gerne auf der Hauptseite meines Boards immer den neuesten Post eines bestimmten Themas anzeigen,
dazu habe ich schon mit folgendem Script das ganze extern zwar lösen können,
wenn ich es aber in mein Board oder Forum einbaue bekomme ich einen mysql-fehler,
ich schätze mal, weil ich durch das Forum bereits eine Mysql-Abfrage habe... nur wie lese ich dann die Daten aus?

Hier der Code für die extern wunderbar funktionierende "anzeigen.php"

Code: Alles auswählen

    <?php
    //    error_reporting(0);
        define('IN_PHPBB', true);

    include_once ('');            //Path to phpBB Config File. Due to some restrictions by PHP, you have to provide complete physical path
    $urlPath = "";                //phpBB URL with respect to root
    $topicnumber = 1;            //Total Post Count to Display
    $posttext = 200;                //Number of Characters to display in Post Text
    $completeurl = "";
    $excludedforums = "6";        //Forum, in dem das betreffende Topic ist
    $extopicid = 203; // Id des gewählten Topics

        $table_topics = $table_prefix. "topics";    //Usually you don't have to change below 4 variables
        $table_forums = $table_prefix. "forums";
        $table_posts = $table_prefix. "posts";
        $table_users = $table_prefix. "users";

    function stripBBCode($text_to_search) {
         $pattern = '|[[\/\!]*?[^\[\]]*?]|si';
         $replace = '';
         return preg_replace($pattern, $replace, $text_to_search);
    }


       
        $link = mysqli_connect("$dbhost", "$dbuser", "$dbpasswd") or die("Could not connect");
        mysqli_select_db("$dbname") or die("Could not select database");
        $sub_query = '';
        if(strlen($excludedforums) > 0) {
            $pieces = explode(",", $excludedforums);
            foreach ($pieces as $exforumid) {
           
    $sub_query .= " t.forum_id = " . $exforumid . ' AND ';
    $sub_query .= " p.topic_id = " . $extopicid . ' AND ';
                }
        }
     
        $query = "SELECT t.topic_id, t.topic_title, t.topic_last_post_id, t.forum_id, p.post_id, p.poster_id, p.post_time, u.user_id, u.username, f.forum_name, p.post_text, p.bbcode_uid, p.bbcode_bitfield, f.forum_desc_options
        FROM $table_topics t, $table_forums f, $table_posts p, $table_users u
        WHERE t.topic_id = p.topic_id AND
        f.forum_id = t.forum_id AND ";



        if(strlen($sub_query) > 0) {
            $query .=  $sub_query ;
        }

        $query .= " t.topic_status <> 2 AND
        p.post_id = t.topic_last_post_id AND
        p.poster_id = u.user_id
        ORDER BY p.post_id DESC LIMIT $topicnumber";
        //echo $query;
        $result = mysql_query($query) or die("Query failed" . mysql_error($link));

        print "<div class=\"typecontent\">";
        if($topicnumber % 2) {
            $x="even";
        } else {
            $x="odd";
        }
        $y=0;
     while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        ++$y;
        if ($y==$topicnumber) {
            $x= $x .  " dataitemlast";
        }
    print "<div class=\"dataitem $x \">
                    <table class=\"plain\">
                        <tr>
                            <td class=\"data\">
                                    <div class=\"itemheader\">".
                      date('d.m.y H:i ', $row["post_time"])."                                     
                                    </div>
                                <div class=\"entry\">" .
                                    substr(stripBBCode($row["post_text"]),0,$posttext) . "
    <br>von <a href=\"$completeurl/memberlist.php?mode=viewprofile&u=$row[user_id] \">".$row["username"]."</a>
                                </div>
                            </td>
                        </tr>
                    </table>
                    </div>";

                    if ($x=="odd") {
                        $x="even";
                    } else {
                        $x="odd";
                    }

    }
    print "<div class=\"clear\"></div></div>";
        mysql_free_result($result);
    //  mysql_close($link);
    ?>
Leider kenn ich mich mit Datenbanken so garnicht aus, was die Sache deutlich erschwert.
Habe mich auch gerade erst mehr recht als schlecht in php eingelesen und fühle mich mit mysql-abfragen heillos überfordert... HIlfe wäre deswegen wirklich gern gesehen!

Also... dann Danke schonmal.

Re: Abfrage des neuesten Posts eines definierten Threats

Verfasst: 12.10.2013 21:38
von Miriam
Schon gesehen?: -> http://www.flying-bits.org/download.php?mod_id=5
Ein bißchen anpassen und schon sollte es Deinen Wünschen entsprechen.