views:

34

answers:

2

Is it possible to get the height of a 'text' field from mysql? Or the number of linebreaks would also work!

I have a table which fetches the 'text' field from my mysql database. The background image of the table is sort of a container... I want the background to change to another (taller) background if the text is vertically high!

Possible, if so how?

Thanks

UPDATE: I am not going to use word wrapping...

+1  A: 

In your query you can count how many instances of '\n' are found. You can do this in javascript or php as well. This wouldn't be totally accurate though if you're word wrapping.

How to do it with php

Alternatively... to grab the height with javascript:

document.getElementById('mytable').clientHeight;
Chris Klepeis
A: 

Very difficult, as you're never going to be able to predict font size with 100% certainty (Users could have enlarged text in their browser, for instance, or be using a different font).

If you want to make 100% sure, you would need to use Javascript to measure the actual size.

Otherwise, for most cases, as @Chris Klepeis says, counting the line breaks should work.

Pekka