Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts

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

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,094
    Thanks
    23
    Thanked 594 Times in 593 Posts
    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

  • #3
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •