Hide the content of a while loop

Discussion in 'PHP' started by izlik, Mar 19, 2013.

  1. #1
    EDIT: Problem solved with a Javascript and a div, sorry for the thread as i just made a misstake :<

    Hello

    I may be in the wrong forum now but im taking a shot at it. I have this peice of code where i get comments out from my database and put them into a while loop to display them on my page, what i was wondering is if there is anyway i can "hide" it all so if someone for example press a link / button saying "show comments" all the information from the mysql query / loop bellow will be displayed ?

    <?php
    $getquery=mysql_query("SELECT * FROM comment WHERE flashid = '$play2' ORDER BY id DESC");
    while($rows=mysql_fetch_assoc($getquery))
    {
        $id=$rows['id'];
        $name=$rows['name'];
        $comment=$rows['comment'];
        $flashid=$rows['flashid'];
     
        echo '<font color="white">' . $name . ' Said:' . '</font>' . '<br>' . '<font color="white">' . $comment . '</font>' . '<hr size="5px" width="500px" color="White" />'
    ;}
    ?>
    PHP:

     
    Last edited: Mar 19, 2013
    izlik, Mar 19, 2013 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    You will want to use javascript to do this. Use this in a division with display="none". Make a javascript link, to change the state of the division to display="inline" or display="block".

    You could alternately do this with visibility, but the content would still take up space.
     
    jestep, Mar 20, 2013 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #3
    Also since this would rely on scripting, the script should add the 'display:none' to the wrapping element instead of hard coding it into the markup -- that way scripting off the comments would still show and be able to be shown. Again, a page should work WITHOUT scripting before you start throwing script at it, and that script should not interfere with how it works without scripting.

    I would actually use a class swap to set the hide/show -- since you could then leverage that for other effects as well like setting an opacity fade in/out using CSS3 transitions.
     
    deathshadow, Mar 22, 2013 IP