Forum Moderators: open

Message Too Old, No Replies

Text Wrap within table columns

odd problem with db-driven site

         

bw3ttt

3:36 am on Jul 6, 2007 (gmt 0)

10+ Year Member



I have a comparison shopping site that uses text from a database. The text is inserted into a 5 column table. Normally the text is inserted properly and the result is 5 even columns. However, occasionally the text data for one of the columns in a row is presented as one large word

e.g. camera,digitalcamera,blue,new

This is causing the column contained this text to expand thereby shrinking the other columns so that they can all fit in the table.

How can I make the text wrap in this situation rather than increase the width of the TD?

vincevincevince

5:52 am on Jul 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem seems to be that there is no space after the comma. You don't mention the language you use to interface with the database.

If you use PHP, then instead of (e.g.):
print "<td>$field</td>";

Do:
print "<td>".preg_replace("/\,([^ ])/",", $1",$field)."</td>";

bw3ttt

3:15 pm on Jul 6, 2007 (gmt 0)

10+ Year Member



I'm using Perl to interface with the DB..

vincevincevince

4:46 pm on Jul 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ah, then just use the preg_replace I have above there as a perl regular expression - it's identical (preg is short for Perl Compatible Regular Expression)

bw3ttt

5:40 pm on Jul 6, 2007 (gmt 0)

10+ Year Member



I will tell the programmer to do so.. Thanks very much Vince!

rocknbil

6:14 pm on Jul 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$field =~ s/,/, /g;