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 09-22-2011, 10:26 PM   PM User | #1
PassivePete
New to the CF scene

 
Join Date: Sep 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
PassivePete is an unknown quantity at this point
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..
PassivePete is offline   Reply With Quote
Old 09-22-2011, 11:28 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
What happens if you only specify the width?
Do not even put-in the height property.


.
mlseim is offline   Reply With Quote
Old 09-22-2011, 11:33 PM   PM User | #3
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,042
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
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
oracleguy is offline   Reply With Quote
Old 09-23-2011, 12:10 AM   PM User | #4
jimhill
Regular Coder

 
Join Date: Jul 2010
Posts: 271
Thanks: 3
Thanked 40 Times in 40 Posts
jimhill is an unknown quantity at this point
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
jimhill 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 08:57 PM.


Advertisement
Log in to turn off these ads.