1

Hi I have a table in which my row contains the text which i retrieve from the database.But i have a small width of row and the data i retrieve is large.And the text exceeds the width of my row so i want to break the data i retrieve into multi lines inside the table row.How can i do it. My code is here:

$list = $mfidao1->fetchMfi($_GET['id']); 
//print_r($list);
//die;
if(!empty($list))
{
foreach($list as $menu)
{
?>

<tr style="border:none; background-color:#FBFBFB;" >
<td class="topv">Social Mission</td>
<td class="topm" ><div class="txt"><?php echo $menu->mfi_1_a;?></div></td>
</tr>
<tr bgcolor="#E8E8E8">
<td class="topv">Address</td>
<td class="topm"><?php echo $menu->mfi_ii_c;?></td>
</tr>
<tr bgcolor="#FBFBFB">
<td class="topv">Phone</td>
<td class="topm"><?php echo $menu->mfi_ii_e;?></td>
</tr>
<tr bgcolor="#E8E8E8">
<td class="topv">Email</td>
<td class="topm"><?php echo $menu->mfi_ii_d;?></td>
</tr>
<tr bgcolor="#FBFBFB">
<td class="topv">Year Established</td>
<td class="topm"><?php echo $menu->mfi_i_c;?></td>
</tr>
<tr bgcolor="#E8E8E8">
<td class="topv">Current Legal Status</td>
<td class="topm"><?php echo $menu->mfi_i_d;?></td>
</tr>
<tr bgcolor="#FBFBFB">
<td class="topv">Respondent</td>
<td class="topm"><?php echo $menu->mfi_ii_a;?></td>
</tr>
<?php
}
}
?>
</table>
S L
  • 14,262
  • 17
  • 77
  • 116
Nyaro
  • 177
  • 3
  • 7
  • 23

6 Answers6

1

Set width of <td>. I think this is the best way to do this rather than word_wrap().

Gaurav Porwal
  • 503
  • 3
  • 6
1

In your css for the table, use "table-layout:fixed" - This fixes the td elements width according to the way you want. " word-wrap: break-word; " - this breaks the text in it so that it doesnt go beyond the boundary of the box.

Ashwin Krishnamurthy
  • 3,750
  • 3
  • 27
  • 49
0

Not sure if this is what you want, but sound like you could use chunk_split()

fabrik
  • 14,094
  • 8
  • 55
  • 71
julioc
  • 109
  • 5
0

You could use the function wordwrap().

It wraps a string to a given number of characters using a string break character.

Michiel Pater
  • 22,377
  • 5
  • 43
  • 57
0

you can either use the php function

php wordwrap

or styling the td with css so that it uses the word-wrap attribute

css wordwrap

fabrik
  • 14,094
  • 8
  • 55
  • 71
sharpner
  • 3,857
  • 3
  • 19
  • 28
0

You need to wrap the text in your td tags. Here is a link to a similar question

Community
  • 1
  • 1
hcb
  • 8,147
  • 1
  • 18
  • 17