Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-25-2012, 12:58 AM   PM User | #1
elitis
Regular Coder

 
Join Date: Sep 2010
Posts: 319
Thanks: 9
Thanked 6 Times in 6 Posts
elitis is an unknown quantity at this point
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..
elitis is offline   Reply With Quote
Old 02-25-2012, 03:41 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,365
Thanks: 18
Thanked 348 Times in 347 Posts
sunfighter is on a distinguished road
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:
Code:
		echo "<a href=\"/reviews?id={$row['id']}\"> Read More...</a>";
	}
}  //ADD THIS ONE
	//Reviews end
sunfighter is offline   Reply With Quote
Old 02-26-2012, 07:15 AM   PM User | #3
elitis
Regular Coder

 
Join Date: Sep 2010
Posts: 319
Thanks: 9
Thanked 6 Times in 6 Posts
elitis is an unknown quantity at this point
Quote:
Originally Posted by sunfighter View Post
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:
Code:
		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.
__________________
Coding is a challenge, get used to it
Always remember to debug
Try the guess & check method
Break it down into simple steps
elitis is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:15 AM.


Advertisement
Log in to turn off these ads.