[SOLVED] My db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

[SOLVED] My db

Post 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>";
 }
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post by pinehead18 »

I'll give a look into it, thank you
Anthony
Post Reply