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
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.