Page 1 of 1

[SOLVED] My db

Posted: Thu Aug 12, 2004 6:07 pm
by pinehead18
Ok, i have a forum which has 3 tables. Forums/threads/topics.

I have a script which pulls the 8 most recent forum posts. I want it to include new topics and thread replies as well. The script that does that is below. Is it possible to add another table for it to do this? OR do i have to put my topics and threads into one table? And identify if a row is a topic or not by an extra field in the table?

Code: Select all

function recent_forum_posts() {

        db_connect('lkcforum');

$sql = "SELECT author,subject,tid FROM threads ORDER BY id DESC LIMIT 0, 8";
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {

        $subject = $row['subject'];
        $tid = $row['tid'];
        $author = $row['author'];
           
           if (strlen($subject) > 15) {
                        $filler = "...";
                        $subject = substr($subject, 0, 15 - $filler) . $filler;
                }
        print "&nbsp;&nbsp;<a href=/forums/viewtopic.php?tid=$tid&fid=$fid>$subject</a><br>&nbsp;&nbsp;&nbsp;By: $author";
        print "<br><br>";
 }
}

Posted: Thu Aug 12, 2004 6:10 pm
by feyd
From what it looks like, you can use a join of some sort (LEFT JOIN probably) to add in the replies to those threads..

Join Syntax

Posted: Thu Aug 12, 2004 6:21 pm
by pinehead18
I'll give a look into it, thank you
Anthony