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 Link to comment https://forums.phpfreaks.com/topic/26511-probably-a-total-newb-mysql-question/ 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? Link to comment https://forums.phpfreaks.com/topic/26511-probably-a-total-newb-mysql-question/#findComment-121282 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 Link to comment https://forums.phpfreaks.com/topic/26511-probably-a-total-newb-mysql-question/#findComment-121283 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] Link to comment https://forums.phpfreaks.com/topic/26511-probably-a-total-newb-mysql-question/#findComment-121898 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. Link to comment https://forums.phpfreaks.com/topic/26511-probably-a-total-newb-mysql-question/#findComment-121900 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.