Jump to content

[SOLVED] Ordering Problem


Noskiw

Recommended Posts

i need help with my ordering

 

forum.php

 

<?php

function isInteger($input){
  return preg_match('@^[-]?[0-9]+$@',$input) == 1;
}

function ShowTopics($forumid){
   $sql =  "SELECT * FROM `forum_topics` WHERE `cid`=$forumid";
   $res = mysql_query($sql) or die(mysql_error());
   if(mysql_num_rows($res) == 0){
      echo "There are no topics in this forum, <a href=\"./forum-index.php?act=create&id=$row[id]\">click here</a> to create a topic!\n";
   } else {
	echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" width=\"100%\" style=\"font-size:12px\">\n";
	echo "<tr><td colspan=\"3\" align=\"right\"><font size=\"3\"><a href=\"./forum-index.php?act=create&id=". $forumid ."\">create topic</a></font></td></tr>\n";
	echo "<tr align=\"center\"><td><font size=\"3\">Title</font></td><td><font size=\"3\">User</font></td><td><font size=\"3\">Date</font></td><td><font size=\"3\"	>Replies</font></td></tr>\n";
	while($row2 = mysql_fetch_assoc($res)){
		$sql3 = "SELECT count(*) AS num_replies FROM forum_replies WHERE tid='".$row2['id']."' ORDER BY time ASC";
		$res3 = mysql_query($sql3) or die(mysql_error());
		$row3 = mysql_fetch_assoc($res3);
		echo "<tr align=\"center\"><td><font size=\"3\"><a href=\"./forum-index.php?act=topic&id=".$row2['id']."\">".s($row2['title'])."</a></font></td><td><font size=\"3\">".uid($row2['uid'])."</font></td><td><font size=\"3\">".$row2['date']."</font></td><td><font size=\"3\">".$row3['num_replies']."</font></td></tr>\n";
	}
	echo "</table>\n";
   	}
}

$id = $_GET['id'];


if(isInteger($id)){
   $sql = "SELECT * FROM `forum_cats` WHERE `id`=$id";
   $res = mysql_query($sql) or die(mysql_error());

   if(mysql_num_rows($res) == 0){
      echo "The forum category you supplied does not exist!\n";
   } else {
      $row = mysql_fetch_assoc($res);
      if($row['admin'] > 0){
         if($admin_user_level > 0){
            ShowTopics($row['id']);
         } else {
            echo "You must be an admin to view this forum!\n";
         }
      } else {
         ShowTopics($row['id']);
      }
   }
}
?>

 

topic.php

 

<?php

$id = $_GET['id'];

$page = (!$_GET['page'] || $_GET['page'] < 0) ? "1" : $_GET['page'];
$page = ceil($page);
$limit = 10;

$start = $limit;
$end = $page*$limit-($limit);

if(isset($id)){
$sql = "SELECT * FROM forum_topics WHERE id='".$id."'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 0){
	echo "This topic does not exist!\n";
}else{
	$row = mysql_fetch_assoc($res);
	$sql2 = "SELECT admin FROM forum_sub_cats WHERE id='".$row['cid']."'";
	$res2 = mysql_query($sql2) or die(mysql_error());
	$row2 = mysql_fetch_assoc($res2);
	if($row2['admin'] == 1 && $admin_user_level == 0){
		echo "You cannot view this topic because you are not an admin!\n";
	}else{
		$a = (isa($row['uid'])) ? "<font style=\"color:#800000;\">ADMIN</font>" : "";

		$amount_check = "SELECT `message` FROM `forum_replies` WHERE `tid`='".$id."'";
		$amount_check_res = mysql_query($amount_check) or die(mysql_error());
		$amount_count = mysql_num_rows($amount_check_res);
		$pages = ceil($amount_count/$limit);

		$previous = ($page-1 <= 0) ? "« Prev" : "<a href=\"./forum-index.php?act=topic&id=".$id."&page=".($page-1)."\">« Prev</a>";
		$nextpage = ($page+1 > $pages) ? " Next »" : " <a href=\"./forum-index.php?act=topic&id=".$id."&page=".($page+1)."\">Next »</a>";

		echo $previous;
		for($i=1;$i<=$pages;$i++){
            	$href = ($page == $i) ? " ".$i." " : " <a href=\"./forum-index.php?act=topic&id=".$id."&page=".$i."\">".$i."</a> ";
   
            	echo $href;
         	}
		echo $nextpage;
		echo "</td></tr>\n";

		echo "<table border=\"0\" width=\"100%\" cellspacing=\"3\" cellpadding=\"3\">\n";
		echo "<tr><td colspan=\"2\" align=\"left\"  class=\"forum_header\"><b><font size=\"3\">".$row['title']."</font></b><font size=\"3\"> - Posted On: <em>".$row['date']."</em></font></td></tr>\n";
		echo "<tr><td align=\"left\" width=\"15%\" valign=\"top\"  class=\"forum_header\">".uid($row['uid'], true)."<br>Posts: ".posts($row['uid'])."<br>".$a."</td>\n";
		echo "<td align=\"left\" valign=\"top\" class=\"forum_header\">";
		echo topic($row['message']);
		echo "</td>\n";
		echo "</tr>\n";

		$select_sql = "SELECT * FROM `forum_replies` WHERE `tid` = ".$id." ORDER BY `id` ASC LIMIT ".$end.", ".$start."";
		$select_res = mysql_query($select_sql) or die(mysql_error()); 

		while($rowr = mysql_fetch_assoc($select_res)){
			echo "<tr><td colspan=\"2\" align=\"left\"  class=\"forum_header\"><font size=\"3\"> - Posted On: <em>".$rowr['date']."</em></font></td></tr>\n";
			echo "<tr><td align=\"left\" width=\"15%\" valign=\"top\"  class=\"forum_header\">".uid($rowr['uid'], true)."<br>Posts: ".posts($rowr['uid'])."<br>".$a."</td>\n";
			echo "<td align=\"left\" valign=\"top\" class=\"forum_header\">";
			echo topic($rowr['message']);
			echo "</td>\n";
			echo "</tr>\n";
		}

		echo "<form method=\"post\" action=\"./forum-index.php?act=reply&id=".$row['id']."\">\n";
		echo "<tr><td colspan=\"2\" align=\"center\"><textarea style=\"width:90%\" name=\"reply\"></textarea><br><input type=\"submit\" name=\"submit\" value=\"add reply!\" style=\"width:90%\" /></td></tr>\n";

		echo "</table>\n";
	}
}
}else{
echo "Please view a valid topic!\n";
}

?>

 

reply.php

 

<?php

if(!$_POST['submit']){
   echo "Invalid Usage of file!\n";
}else{
   $tid = $_GET['id'];
   $msg = $_POST['reply'];

      if(!$tid){
      echo "You did not supply a topic to reply to!\n";
   }else{
      $sql = "SELECT * FROM forum_topics WHERE id='$tid'";
      $res = mysql_query($sql) or die(mysql_error());
      if(mysql_num_rows($res) == 0){
         echo "This topic does not exist!\n";
      }else{
         $row = mysql_fetch_assoc($res);
         $sql2 = "SELECT admin FROM forum_sub_cats WHERE id='{$row['cid']}'";
         $res2 = mysql_query($sql2) or die(mysql_error());
         $row2 = mysql_fetch_assoc($res2);
         if($row2['admin'] == 1 && $admin_user_level == 0){
            echo "You cannot post here, this is because you are not an admin!\n";
         }else{
            if(!$msg){
               echo "You did not supply a message for the reply!\n";
            }else{
               if(strlen($msg) < 10 || strlen($msg) > 10000){
                  echo "Your reply must be between 10 and 10000 characters!\n";
               }else{
                  $sessionuid = $_SESSION['uid'];
                  $date = date("m-d-y") . " at " . date("h:i:s");
                  $time = time();
                  $sql3 = "INSERT INTO `forum_replies` (`tid`,`uid`,`message`,`date`,`time`) VALUES('".$tid."','".$_SESSION['uid']."','".$msg."','".$date."','".$time."')";
                  $res3 = mysql_query($sql3) or die(mysql_error());
                  $sql4 = "UPDATE `forum_topics` SET `time`='".time()."' WHERE `id`='".$tid."'";
                  $res4 = mysql_query($sql4) or die(mysql_error());
                  header("Location: forum-index.php?act=topic&id=".$tid);
               }
            }
         }
      }
   }
}

?>

 

basically what i wan't it to do is when the user posts on a topic that is currently at the bottom of the page, i want it to go to the top, unfortunently it doesn't do that, and it has to be in one of these three but i can't find it.

Link to comment
https://forums.phpfreaks.com/topic/137753-solved-ordering-problem/
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.