Jump to content

Probably a total newb mysql question


DaveLinger

Recommended Posts

So I'm trying to make a "latest threads" box for my site's homepage. I've got it working really well except that I need to somehow only select one result per thread. We're running Vbulletin so each row in the posts table has a post id and the thread id that it belongs to. Right now I have my SQL query sorting by the thread ID and returning 5 results, but that also gets the thread replies with the same thread id, you know? So I just need to know how to only select one row for each thread id. Meh

Thanks
Link to comment
https://forums.phpfreaks.com/topic/26511-probably-a-total-newb-mysql-question/
Share on other sites

here's my code to retrieve the "most recent" thread.

[code]        $query="SELECT * FROM vbulletin_post ORDER BY threadid DESC LIMIT 1";
        $result=mysql_query($query);

        while ($row = mysql_fetch_array($result)) {
                $name = $row['username'];
                $id = $row['userid'];
$topic = $row['threadid'];
$title = $row['title'];
        }
        echo "<li class=\"forumpost\"><a href=\"forums/showthread.php?goto=newpost&amp;t=$topic\">\"$title\"</a><br /><span class=\"forumposter\">by <a href=\"forums/member.php?u=$id\" class=\"poster\">$name</a></span></li>";[/code]

Here's a screen of the db structure:

[img]http://www.davessonicsite.com/db.gif[/img]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.