Needing help with making stickies appear at the top

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
beloveddoll
Forum Commoner
Posts: 40
Joined: Sat Jul 14, 2007 6:18 pm

Needing help with making stickies appear at the top

Post by beloveddoll »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am trying to get the forum to show sticky messages at the top with non-sticky messages below the stickies (I`m sure you`re familiar with nearly al forums doing this). But I can`t figure out how to get it to display that way. I have all the fields available for this in the database. But I can`t figure out how to get the php to work the way I need it to. Here`s what I`ve got:

Code: Select all

<table border=0 width=100%><? //5
?>
<tr>
<td><b>Topic</b><td width=20%><b>Creator</b><td width=9%><b>Created</b><td width=8%><b>Replies</b><td width=9%><b>Update</b>
<? 
  $recent = 0;
  $res = mysql_query("SELECT id,user,subject,datetime,message_text,forum_id,recent,login,repl,sticky FROM forum WHERE forum_id=$id ORDER BY recent DESC")or die( mysql_error() );  
  while( ($fort = mysql_fetch_row($res)) && $recent < 25 ){
    if( $recent%1 == 0 ){
	    
	echo "<tr><td bgcolor='312D37'><td bgcolor='312D37'><td bgcolor='312D37'><td bgcolor='312D37'><td bgcolor='312D37'><tr>";
    }
    $recent = $recent + 1;
    echo "<td><font size=2><a href='thread.php?id=$fort[0]'>$fort[2]</a></font>";
    echo "<td><font size=2><a href='trancer.php?id=$fort[1]'>$fort[7]</a></font>";
    echo "<td><font size=2>$fort[3] </font><td><font size=2>$numCom[0] </font><td><font size=2>$fort[6] </font>";	
  }
?>
</table><? //5
?>
It will display the threads just fine but I need the stickies to stick on top of the list. For the sticky field, 0 is for not a sticky message, and 1 is for sticky message.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]2.[/b] Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.[/quote]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try ORDER BY sticky DESC, recent DESC
beloveddoll
Forum Commoner
Posts: 40
Joined: Sat Jul 14, 2007 6:18 pm

Post by beloveddoll »

Yes, that did the trick. Thank you very much!
Post Reply