Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] Forum Pinned Threads


[SOLVED] Forum Pinned Threads

Reply
  #1 (permalink)  
Old 05-15-08, 09:09 AM
-NM- -NM- is offline
Newbie Coder
 
Join Date: May 2008
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Forum Pinned Threads

Okay, in the forum i am building, it displays threads by ordering them by the last reply:

PHP Code:

$threaddata "SELECT * FROM `threads`WHERE forum_id='$forum_id' ORDER BY  `threads`.`thread_last_reply`DESC";

$threadresult mysql_query($threaddata$dbc); 
But some threads are pinned, and i want them to always stay at the top, regardless of their last reply. So how would i go about this?

Would i have to create two different sections? The first one for all the pinned threads and the 2nd for all the rest? Or is there some way to tell it to always have them at the top?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 05-15-08, 09:39 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Maybe like this:
PHP Code:

<?php
$threaddata 
"SELECT * FROM threads WHERE forum_id='$forum_id' ORDER BY  threads.pinned ASC, threads.thread_last_reply DESC";
?>
__________________
Jerry Broughton
Reply With Quote
  #3 (permalink)  
Old 05-15-08, 09:39 AM
kjarli kjarli is offline
Newbie Coder
 
Join Date: May 2008
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
You should first check if there ARE pinned threads. If not, just load the threads, if there are, load them first.
Reply With Quote
  #4 (permalink)  
Old 05-15-08, 09:48 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
My query will sort them and always have the pinned ones on top.
You just need to print them out.
__________________
Jerry Broughton
Reply With Quote
  #5 (permalink)  
Old 05-15-08, 09:49 AM
-NM- -NM- is offline
Newbie Coder
 
Join Date: May 2008
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by job0107 View Post
Maybe like this:
PHP Code:

<?php
$threaddata 
"SELECT * FROM threads WHERE forum_id='$forum_id' ORDER BY  threads.pinned DESC, threads.thread_last_reply DESC";
?>
Yes that worked, thank you.
Reply With Quote
  #6 (permalink)  
Old 05-15-08, 09:54 AM
kjarli kjarli is offline
Newbie Coder
 
Join Date: May 2008
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
K, nice ill safe it since im building a forum too

Depends on what the values of pinned is (in my case tinyint[1]), so i have to use the DESC like you said, though when you use something like enum ('yes', 'no'), you have to watch the Y and N
Reply With Quote
  #7 (permalink)  
Old 05-15-08, 09:59 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Quote:
Originally Posted by -NM- View Post
Yes that worked, thank you.
Your welcome. My pleasure.

Cheers...
__________________
Jerry Broughton
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Latest forum threads on main page? Evo PHP 2 02-15-06 09:21 AM
.::Figure This::. Community Forum grand merlin General Advertisements 1 01-01-06 08:20 PM
Free phpBB Forum Hosting - Jconserv's FFH Network Psan General Advertisements 0 05-13-05 05:30 PM


All times are GMT -5. The time now is 07:43 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.