...

View Full Version : Resolved Comment box echoed multiple times



elitis
02-25-2012, 12:58 AM
There are basically two comment boxes, though both are only visible simultaneously when you click one of the reply links (this comment box appears under the comment you're replying to). The other comment box is supposed to appear at the bottom of all the comments by itself. But it is being echoed under every comment. I've tried moving the code around, multiple if statements but it doesn't seem to work.


<?php
//Reviews start
$result = mysql_query("SELECT * FROM `reviews` ORDER BY `date` DESC LIMIT 10");
while($row = mysql_fetch_array($result))
{
if ($_GET['id'] == $row['id'])
{
echo $row['title'];
echo "<br />";
echo $row['review'];
echo "<br />";
echo $row['date'];
echo "<h1 class='centered'>Comments</h1>";
}
else
{
echo "<div class='box3'>";
echo $row['title'];
echo "<br />";
echo $row['description'];
echo "<br />";
echo $row['date'];
echo "<a href=\"/reviews?id={$row['id']}\"> Read More...</a>";
}
//Reviews end

//Comments start
$result = mysql_query("SELECT * FROM `comments` WHERE `category` = 'reviews' AND `subcategory` = '$row[id]' ORDER BY `date` DESC LIMIT 20");
while($comments = mysql_fetch_array($result))
{
if ($_GET['id'] == $row['id'])
{
echo "<br />";
echo "<div class='box'>";
echo $comments['username'];
echo "<br />";
echo $comments['comment'];
echo "<br />";
echo $comments['date'];
echo "<a href=\"/reviews?id={$row['id']}&reply={$comments['id']}\"> Reply</a>";
//Replies start
if ($_GET['reply'] == $comments['id'])
{
echo "
<form action='/reviews/' method='POST'>
<input class='field' type='text' name='name' value='Name' required='required' />
<br />
<textarea class='field' name='comment' rows='2' cols='55' required='required'>Type your comment here...</textarea>
<input class='specialbutton' type='submit' name='submit' value='Post Comment' />
<input type='hidden' name='submitted' value='1' />
</form>";
}
//Replies end
echo "
<form action='/reviews/' method='POST'>
<input class='field' type='text' name='name' value='Name' required='required' />
<br />
<textarea class='field' name='comment' rows='2' cols='55' required='required'>Type your comment here...</textarea>
<input class='specialbutton' type='submit' name='submit' value='Post Comment' />
<input type='hidden' name='submitted' value='1' />
</form>";
echo "<br />
</div>";
//Comments end
}
}

sunfighter
02-25-2012, 03:41 PM
You run out of steam at the end of your code. Your missing the ?> and a curly bracket for the first while statement. Everything depends on where you put this bracket. Tracing back it seems it should be added to the end of the code and that would cause your problems. The correct place is before the "Reviews end' comment".

Find where you have it and then remove it and put it in correct place:


echo "<a href=\"/reviews?id={$row['id']}\"> Read More...</a>";
}
} //ADD THIS ONE
//Reviews end

elitis
02-26-2012, 07:15 AM
You run out of steam at the end of your code. Your missing the ?> and a curly bracket for the first while statement. Everything depends on where you put this bracket. Tracing back it seems it should be added to the end of the code and that would cause your problems. The correct place is before the "Reviews end' comment".

Find where you have it and then remove it and put it in correct place:


echo "<a href=\"/reviews?id={$row['id']}\"> Read More...</a>";
}
} //ADD THIS ONE
//Reviews end


Just as it said I resolved this a few minutes after posting. And I didn't post the entire page of code, as I didn't think it was necessary. I had all the brackets and and the end tag, though as you said one bracket was misplaced.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum