Jump to content

newest topic/reply "float to top"


eaglelegend

Recommended Posts

Hey, urrm, I startest to notice that my forums are getting quite big, hehe, now how could I make the ltest reply, or topic automatically "float to the top" of the list of topics? also, how would I be able to make it show whose replied and time? I know it sounds like alot of work, well to me it does but help is much appreciated! heres the code:

<?php
session_start();
include("header.php");
include("members.php");

$a = $_GET['action'];

if($a == '') {
print "<h2>Forum</h2><p>";
?>
<input type='button' value='New Topic!' onClick='parent.location="/forum.php?action=new_topic"' class='text_box' style='width: 200px' alt='Create a new topic!' title='Create a new topic!'>
<?php
if($message) {
 	print "$message<p>";
}

print "<table border=0 cellpadding=2 cellspacing=0 width=100%>
 <tr>
  <td class=text_box alt='The name of the topic!' title='The name of the topic!'><b>Topic</b></td>
  <td class=text_box align=center alt='The author of the topic!' title='The author of the topic!'><b>Author</b></td>
  <td class=text_box align=center alt='The date the topic was made!' title='The date the topic was made!'><b>Date</b></td>
  <td class=text_box align=center alt='How many replys the topic has had!' title='How many replys the topic has had!'><b>Replies</b></td>";?>
  	<?php

$ch = mysql_num_rows(mysql_query("SELECT * FROM `members` WHERE `username`='{$_SESSION['ELv2']}' AND `admin`='1'"));

if($ch == 1) {
	?>
  <td class=text_box align=center alt='Action, how you can mod this forum!' title='Action, how you can mod this forum!'><b>Action</b></td>
<?php
}
?>	  
 <?php print "</tr>";

 $sql = mysql_query("SELECT * FROM `forum` WHERE `threadID`='0' AND `site`=\"$Z\" ORDER BY `id` DESC");
 while($row = mysql_fetch_array($sql)) {
	extract($row);

	$x=$x+1;
	if($x%2==0) {
	 	$one = "forumone";
	}
	else {
	 	$one = "forumtwo";
	}

	$replies = mysql_num_rows(mysql_query("SELECT * FROM `forum` WHERE `threadID`='$id' AND `site`=\"$Z\""));

	print "<tr>
	 <td class='$one' width=40%><a href='/forum.php?action=view&topicID=$id'>$title</a></td>
	 <td class='$one' align=center width=20%>$user</td>
	 <td class='$one' align=center width=20%>$date</td>
	 <td class='$one' align=center width=20%>$replies</td>";?>
  	<?php

$ch = mysql_num_rows(mysql_query("SELECT * FROM `members` WHERE `username`='{$_session['ELv2']}' AND `admin`='1'"));

if($ch == 1) {
	?>
    <?php print"<td class='$one' align=center width=20%>$action</td>";?>
<?php
}
?>	  
 <?php print "</tr>";
 }

print "</table>"; 
}
else {
	if($a == 'view') {
	 	$topicID = $_GET['topicID'];

 	if($topicID == '') {
	  	Header("Location: /forum.php");
	}
	else {
		$sql = mysql_query("SELECT * FROM `forum` WHERE `id`='$topicID' AND `site`=\"$Z\"");
		while($row = mysql_fetch_array($sql)) {
		 	extract($row);

			print "<h2>Viewing Topic: $title</h2>";
			?>
            <input type='button' value='Back!' onClick='parent.location="/forum.php"' class='text_box' style='width: 200px' alt='Back to Forum' title='Back to Forum'>
            <?php				
			print "<table border=0 cellpadding=3 cellspacing=0 width=100%>
			 <tr>
			  <td valign=top width=20% class='forumone'><b>$user</b><p>
			  posted on: $date</td>
			  <td valign=top width=80% class='forumtwo'>$text</td>
			 </tr>
			</table><p>";	 
		} 

		$text = "";
		$user = "";
		$date = "";

		print "<h2>Replies</h2><p>";

		$sql = mysql_query("SELECT * FROM `forum` WHERE `threadID`='$topicID' AND `site`=\"$Z\"");
		$num = mysql_num_rows($sql);

		if($num > 0) {
			while($row = mysql_fetch_array($sql)) {
			 	extract($row);
				$x=$x+1;
				print "<table border=0 cellpadding=3 cellspacing=0 width=100%>
			 	 <tr>
			 	  <td valign=top class='forumone' width=5%><h2>$x</h2></td>
			  	  <td valign=top class='forumone' width=15%><b>$user</b><p>
			  	  posted on: $date</td>
			  	  <td valign=top class='forumtwo' width=80%>$text</td>
			 	 </tr>
				</table><br>"; 
			}
		}
		else {
		 	print "<i>No replies yet!</i>";
		}

		print "<h2>Add a Reply</h2>";

		print "<form action='/forum.php?action=reply&topicID=$topicID' method='post'>
		<textarea rows=5 cols=50 nowrap name='reply' class='text_box' alt='Please enter your replay!' title='Please enter your reply!'></textarea><p>
		<input type='submit' value=' Add Reply ' class='text_box' alt='Post your reply!' title='Post your reply!'></form>";

	} 	
	}

if($a == 'reply') {
	$reply = $_POST['reply'];
	$date = date("m/d/y g:i A");
	$user = $_SESSION['ELv2'];
	$id = $_GET['topicID'];

	if($reply && $id) {
	 	$reply = str_replace("<","<",$reply);

		$insert = mysql_query("INSERT INTO `forum` (`site`, `threadID`, `date`, `user`, `text`) VALUES(\"$Z\", '$id', '$date', \"$user\", \"$reply\")");

		if($insert) {
		 	Header("Location: /forum.php?action=view&topicID=$id");
		}
		else {
		 	print mysql_error();
		}
	}
	else {
	 	print "Reply and ID required!";
	}	 
}

	if($a == 'new_topic') {
		print "<h2>New Topic</h2><p>
	<form action='/forum.php?action=post_topic' method='post'>
	<b>Title</b><br>
	<input type='text' name='title' size='50' class='text_box' alt='Please enter a title!' title='Please enter a title!'><p>
	<b>Post</b><br>
	<textarea rows=10 cols=60 nowrap name='text' class='text_box' alt='Now enter your message!' title='Now enter your message!'></textarea><p>
	<input type='submit' value=' Post Topic ' class='text_box' alt='Post your topic' title='Post your topic!'></form>"; 
	}

if($a == 'post_topic') {
	$title = $_POST['title'];
	$text = $_POST['text'];

	$text = str_replace("<","<",$text);
	$title = str_replace("<","<",$title);

	if($text && $title) {
		$user = $_SESSION['ELv2'];
		$date = date("m/d/y g:i A");

		$insert = mysql_query("INSERT INTO `forum` (`site`, `user`, `title`, `date`, `text`) VALUES(\"$Z\", \"$user\", \"$title\", '$date', \"$text\")");

		if($insert) {
		 	Header("Location: /forum.php?message=Your topic has been posted!");
		}
		else {
		 	print mysql_error();
		} 
	} 
	else {
	 	print "Title and Post are required";
	}
}

}

include("footer.php");
?>

Link to comment
https://forums.phpfreaks.com/topic/106203-newest-topicreply-float-to-top/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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