Jump to content

PHP - Nested Quote replies


rEhSi_123

Recommended Posts

Hello everybody, dont know if the above title is appropriate for my query....

 

But here it goes.... ;)

 

I created a .php files for replying to a comment. Now I am able to get the previous message on my text box in which I will reply but I want the message in quotes.......like below:

hello world!

 

I know everybody will say to install or create bbcodes but I am only creating a basic forum so not going fancy....

 

here is my code:

<?php


if(!$_SESSION['uid']){
header("Location: index.php");
}

   $msg = mss($_POST['reply']);
   $tid = mss($_GET['id']);
   $reply_id = $_GET['reply_id'];
   $id = $_GET['id'];

   if($tid){
      echo $reply_id;
  
      $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!";
      }else {
      $sql = "SELECT * FROM `forum_replies` WHERE `id`='".$reply_id."'";
  $res = mysql_query($sql) or die(mysql_error());
  $row = mysql_fetch_assoc($res);
      if(!$_POST['submit']){
		  echo "<form method=\"post\" action=\"./index.php?act=test&id=".$row['tid']."&reply_id=".$reply_id."\">\n";
		  echo "<table border=\"0\" width=\"100%\" cellspacing=\"3\" cellpadding=\"3\">\n";             
	echo "<tr><td colspan=\"2\" align=\"center\"><textarea style=\"width:90%;height:200px\" name=\"reply\">[quote]".$row['message']."[/quote]</textarea><br><input type=\"submit\" name=\"submit\" value=\"Add Reply\" stlye=\"width:90%\"></td></tr>\n";
         echo "</table>\n";
	 }else{
		if($row2['admin'] == 1 && $admin_user_level == 0){
		echo "You do not have sufficient priveleges to add a reply to this topic";
	 }else {
		if(!$msg){
				echo "You did not supply a reply";
					}else {
					if(strlen($msg) < 10 || strlen($msg) > 10000){
					echo "Your reply must be between 10 and 10,000 characters!";
					}else {
					 $date = date("d-m-y") ." at ". date("h-i-s");
					 $time = time();
					 $sql4 = "INSERT INTO `forum_replies` (`tid`,`uid`,`message`,`date`,`time`,`reply_id`) VALUES('".$tid."','".$_SESSION['uid']."','".$msg."','".$date."','".$time."','".$reply_id."')";
					 $res4 = mysql_query($sql4) or die(mysql_error());
					 header("Location: ./index.php?act=topic&id=".$tid); 
					 }                   
				  }      
				}
			  }
			}   
		  }         
?>


 

So therefore I just want the $row['message'] part in quotes once I click on 'reply'

 

Thanks

Link to comment
Share on other sites

<?php
echo "<tr><td colspan=\"2\" align=\"center\"><textarea style=\"width:90%;height:200px\" name=\"reply\">[quote]\"".$row['message']."\"[/quote]</textarea><br><input type=\"submit\" name=\"submit\" value=\"Add Reply\" stlye=\"width:90%\"></td></tr>\n";
?>

Link to comment
Share on other sites

<?php
echo "<tr><td colspan=\"2\" align=\"center\"><textarea style=\"width:90%;height:200px\" name=\"reply\">[quote]\"".$row['message']."\"[/quote]</textarea><br><input type=\"submit\" name=\"submit\" value=\"Add Reply\" stlye=\"width:90%\"></td></tr>\n";
?>

 

Thanks for the reply man.....but the above didn't work :-[

 

its displaying message like this:

"Hello" how are you?

Link to comment
Share on other sites

Where is your code for displaying this data?

 

<?php

error_reporting(E_ALL ^ E_NOTICE); //Report all error except NOTICES
$id = mss($_GET['id']);
$page = (!$_GET['page'] || $_GET['page'] < 0) ? "1" : $_GET['page'];
$page = ceil($page);

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

if($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 exists!";
	}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!";
			}else {
				$a = (isa($row['uid'])) ? "<font style=\"color:#800000;\">ADMIN</font>" : "";
				echo "<table border=\"0\" width=\"100%\"cellspacing=\"3\" cellpadding=\"3\">\n";
				echo "<tr><td colspan=\"2\" align=\"left\" class=\"forum_header\"><b>".$row['title']."</b>- Posted on: <em>".$row['date']."</em></td></tr>\n";
				echo "<tr><td align=\"left\" width=\"15%\" valign=\"top\" class=\"forum_header\">".uid($row['uid'],true)."<br>Post Count: ".post($row['uid'])."</br>".$a."</td>\n";
				echo "<td align=\"left\" valign=\"top\" class=\"forum_header\">\n";
				echo topic($row['message']);
				echo "</td>\n";
				echo "</tr>\n";
				$amount_check = "SELECT * 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=\"./index.php?act=topic&id=".$id."&page=".($page-1)."\">« Prev</a>";
				$nextpage = ($page+1 > $pages) ? "Next »" : "<a href=\"./index.php?act=topic&id=".$id."&page=".($page+1)."\">Next »</a>";
				echo "<tr><td align=\"right\" colspan=\"2\" class=\"forum_header\">\n";
				echo "Pages: ";
				echo $previous;
				for($i=1;$i<=$pages;$i++){
					$href = ($page == $i) ? " ".$i." " : " <a href=\"./index.php?act=topic&id=".$id."&page=".$i."\">".$i."</a> ";
					echo $href;
				}
				echo $nextpage;
				echo "</td></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\">Posted on: <em>".$rowr['date']."</em></td></tr>\n";
				echo "<tr><td align=\"left\" width=\"15%\" valign=\"top\" class=\"forum_header\">".uid($rowr['uid'],true)."<br>Post Count: ".post($rowr['uid'])."</br>".$a."</td>\n";
				echo "<td align=\"left\" valign=\"top\" class=\"forum_header\">\n";
				echo topic($rowr['message']);
				if($rowr['edit_time'] > 0){
					echo "<tr><td align=\"left\" colspan=\"3\" class=\"forum_header\"><em>Edited at:".date("l jS \of F Y",$rowr['edit_time']) . " at " . date("h:i:s",$rowr['edit_time'])."</em></td></tr>\n";
					}
				$adminz = isa($_SESSION['uid']);
				if($adminz == 1 || $rowr['uid'] == $_SESSION['uid']){
					echo "<tr><td align=\"right\" colspan=\"2\"><a href=\"index.php?act=mod&act2=reply&id=".$rowr['id']."\"><img src=\"edit.gif\"></a> <a href=\"index.php?act=mod&act2=topic&id=".$rowr['id']."\" onclick=\"return confirm('Are you sure you want to delete?')\"><img src=\"delete.gif\"></a> <a href=\"index.php?act=test&id=".$rowr['tid']."&reply_id=".$rowr['id']."\"><img src=\"quoteIcon.gif\"></a></td></tr>\n";					}
				echo "</td>\n";
				echo "</tr>\n";
				}
				echo "<tr><td colspan=\"2\" align=\"left\"><a href=\"./index.php?act=reply&id=".$row['id']."\">Reply Now</a></td></tr>\n";					
				echo "</table>\n";
				  }  
					}
						}else {
								echo "Please view a valid topic!";
							  }
?>

Link to comment
Share on other sites

You might want to narrow your code down to the part that actually displays the message you want quotes. besides, all you need do is wrap that part within the relevent html. There really isn't such a thing a a html 'quote', so its pretty unclear what your after.

Link to comment
Share on other sites

hello

 

What I am after is exactly as above ^^^

 

So when a user replies to a user comment he/she clicks on the rply button which then displays this part of the code:

if(!$_POST['submit']){
           echo "<form method=\"post\" action=\"./index.php?act=test&id=".$row['tid']."&reply_id=".$reply_id."\">\n";
           echo "<table border=\"0\" width=\"100%\" cellspacing=\"3\" cellpadding=\"3\">\n";             
      echo "<tr><td colspan=\"2\" align=\"center\"><textarea style=\"width:90%;height:200px\" name=\"reply\">[quote]".$row['message']."[/quote]</textarea><br><input type=\"submit\" name=\"submit\" value=\"Add Reply\" stlye=\"width:90%\"></td></tr>\n";
         echo "</table>\n";

 

The above html form also displays the previous message to which the user is replying.....OK!

 

Therefore once the user finishes typing the message, user then click on Add Reply.

 

This then takes the message along with the previous message back to the main thread......to which the code is present in the topic.php I posted in reply to your request.

 

Hope you can understand what I am after ;D

 

So finally I want the previous message displayed in QUOTES as above along with new comment left by the user.

 

Cheers

 

Link to comment
Share on other sites

Yeah, thats kinda what I thought you where hinting at.

 

Not as simple as that I'm afraid. This really isn't something your going to get a solution to in a simple forum post. Your probably better off looking at some open source forums to see how they do it.

 

Theres quite a bit of work involved in getting something like that (assuming you mean something like the way this board works) working.

Link to comment
Share on other sites

Yeah, thats kinda what I thought you where hinting at.

 

Not as simple as that I'm afraid. This really isn't something your going to get a solution to in a simple forum post. Your probably better off looking at some open source forums to see how they do it.

 

Theres quite a bit of work involved in getting something like that (assuming you mean something like the way this board works) working.

 

Right :-[

 

Would you recommend using bbcode or something......I only want the quote thingy to work.....but since you are saying its not easy :'(

Link to comment
Share on other sites

bbcode is just a simpler syntax to html, its not really needed.

 

If all you want is your replies to be within a styled box, use <span> tags to put them in one. Then you can use css to style that box. this really hasn't anything to do with php.

 

If on the other hand you want when users click

the text they are quoting is placed within the textarea, that requires javascript. From there you will likely want to parse that inserted text using some form of bbcode.

Link to comment
Share on other sites

bbcode is just a simpler syntax to html, its not really needed.

 

If all you want is your replies to be within a styled box, use <span> tags to put them in one. Then you can use css to style that box. this really hasn't anything to do with php.

 

If on the other hand you want when users click

the text they are quoting is placed within the textarea, that requires javascript. From there you will likely want to parse that inserted text using some form of bbcode.

 

Well I tried using span tags but it didn't seem to work.......

 

 

Link to comment
Share on other sites

Anybody here who could further help me solve my problem.......

 

I am really not fussed about having quote box or want the user to input

boxes, all I would like to have be a simple box around the previous message so that it distinguishes it from the new message.

 

Please Please Advice.....

 

Thanks

Link to comment
Share on other sites

Additionaly if the data is being pulled from the database, just prepend the string with ' " ' and then append it with ' " '.

 

Sorry for being a dumb...

 

Could please give me example?as ian still learning php.

 

As my old message is in a array form...

$row['message'] if u check my previous posts.

 

 

Thanks

Link to comment
Share on other sites

<?php
echo "<tr><td colspan=\"2\" align=\"center\"><textarea style=\"width:90%;height:200px\" name=\"reply\">".' " '.$row['message'].' " '."</textarea><br><input type=\"submit\" name=\"submit\" value=\"Add Reply\" stlye=\"width:90%\"></td></tr>\n";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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