Jump to content

wrap text in HTML tables


raman

Recommended Posts

Though I give fixed width attribute for each <td> tag , when the data in the cell is too long it extends further and I have to scroll thru the browser to read the entire data.I want the text to wrap after a certain convenient limit even if there are no new line characters in the cell data.

 

I have the PHP script as under:

 

<?php

$con= mysql_connect("localhost","root","passor3");

if(!$con)

  {

    die('Could not connect:'.mysql_error());

  }

mysql_select_db("Protvirdb",$con);

 

$key=$HTTP_GET_VARS["sn"];

$rer=mysql_query("SELECT * FROM cryptovir WHERE SNo='$key'");

 

$special=mysql_fetch_array($rer);

 

echo"<table align='center' border='2' width='620'>

<tr><th BGCOLOR='#99CCFF' width='20'>Protein name</th>";

echo"<td width='600'>".$special['Name']."</td></tr>";

echo"</tr>

<th BGCOLOR='#99CCFF' width='20'>Accession number</th>";

echo"<td width='600'>".$special['Accession']."</td></tr>";

echo"<tr>

<th BGCOLOR='#99CCFF' width='20' >Pubmed Id </th>";

echo"<td width='600'>".$special['PMID']."</td></tr>";

echo"<tr>

<th BGCOLOR='#99CCFF' width='20'>Sequence</th>";

echo"<td width='600'>".$special['Sequence']."</td></tr>";

echo"</table>";

?>

Link to comment
https://forums.phpfreaks.com/topic/125418-wrap-text-in-html-tables/
Share on other sites



<?php
$con= mysql_connect("localhost","root","pichii13");
if(!$con)
  {
    die('Could not connect:'.mysql_error());
  }
mysql_select_db("Protvirdb",$con);

$key=$HTTP_GET_VARS["sn"];
$rer=mysql_query("SELECT * FROM cryptovir WHERE SNo='$key'");

$special=mysql_fetch_array($rer);
$pd=$special['PMID'];
$newpd= wordwrap($pd,20,"<br />\n","TRUE");

echo"<table align='center' border='2' width='620'>
<tr><th BGCOLOR='#99CCFF' width='20'>Protein name</th>";
echo"<td width='600'>".$special['Name']."</td></tr>";
echo"</tr>
<th BGCOLOR='#99CCFF' width='20'>Accession number</th>";
echo"<td width='600'>".$special['Accession']."</td></tr>";
echo"<tr>
<th BGCOLOR='#99CCFF' width='20' >Pubmed Id </th>";
echo"<td width='600'>".$newpd."</td></tr>";
echo"<tr>
<th BGCOLOR='#99CCFF' width='20'>Sequence</th>";
echo"<td width='600'>".$special['Sequence']."</td></tr>";
echo"</table>";
?>

 

Even after using wordwrap function I found no difference at all in the output.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.