|
Comment box echoed multiple times
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.
Code:
<?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
}
}
__________________
Coding is a challenge, get used to it
Always remember to debug
Try the guess & check method
Break it down into simple steps
Last edited by elitis; 02-25-2012 at 01:18 AM..
|