DaveLinger Posted November 7, 2006 Share Posted November 7, 2006 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. MehThanks Quote Link to comment Share on other sites More sharing options...
bqallover Posted November 7, 2006 Share Posted November 7, 2006 Sorry, I'm not familliar with vBulletin, but maybe something to do with the DISTNCT keyword? Quote Link to comment Share on other sites More sharing options...
stewart715 Posted November 7, 2006 Share Posted November 7, 2006 Post the code that is outputting only one result please Quote Link to comment Share on other sites More sharing options...
DaveLinger Posted November 9, 2006 Author Share Posted November 9, 2006 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&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] Quote Link to comment Share on other sites More sharing options...
DaveLinger Posted November 9, 2006 Author Share Posted November 9, 2006 d'oh! I got it! I just changed my code to say "WHERE parentid='0'", and it works. Thanks for your concern, though. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.