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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Automatic <div> height in PHP while loop

    Hi,

    I'm querying through a database and creating a div for every result using a while loop:
    PHP Code:
    while($row mysql_fetch_array($result))
      {
      echo 
    "<div id='search_results'><h3>" xml_encode($row['comment']) . "</h3>";</div>
      } 
    My problem is that I want my div height to vary depending on the size of the comment. I tried adding a style='height:auto' to both the div itself and also in the CSS but it won't make the div height change for larger comments.

    Does anyone know how to get auto div heights in php while loops?

    Cheers,

    Pierre
    Last edited by PassivePete; 09-22-2011 at 10:44 PM.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    What happens if you only specify the width?
    Do not even put-in the height property.


    .

  • #3
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Also keep in mind that for correct HTML IDs need to be unique there can only be one element on the page with a given ID. Otherwise you should be using the class attribute instead.
    OracleGuy

  • #4
    Regular Coder
    Join Date
    Jul 2010
    Posts
    271
    Thanks
    3
    Thanked 40 Times in 40 Posts
    Just use a class and set overflow to inherit
    PHP Code:
    <head>
    <style type="text/css">
        .search_results {
        height:100px;
        width:200px;
        overflow:inherit;
        }
    </style>
    </head>
    <body>
    <?php

    while($row mysql_fetch_array($result))
      {
      echo 
    "<div id='search_results' class='search_results'><h3>" xml_encode($row['comment']) . "</h3>";</div>
      }
    If you can't stand behind your troops, feel free to stand in front of them
    Semper Fidelis


  •  

    Posting Permissions

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