How to make a column data adjust itself to the width of the cell

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Appu2008
    New Member
    • Dec 2007
    • 18

    How to make a column data adjust itself to the width of the cell

    Hi,
    Iam making a report based on some database values. The fields are displayed in different columns of a table(Iam using php+mysql). My problem is that how can I make the width of a column fixed and make the data insert new line itself whenever the content exceed the width.

    Thanks & Regards,
    Appu
  • sandeepsandeep
    New Member
    • Dec 2006
    • 50

    #2
    Originally posted by Appu2008
    Hi,
    Iam making a report based on some database values. The fields are displayed in different columns of a table(Iam using php+mysql). My problem is that how can I make the width of a column fixed and make the data insert new line itself whenever the content exceed the width.

    Thanks & Regards,
    Appu
    Hi,
    Fix the width of table and every column in numbering.
    [code=html]<table width="500"></table>
    <tr><td width="300"></td>
    <td width="200"></td>
    </tr>
    </table>[/code]

    so whenever first column data is exeed the width then it will be start from new line
    Last edited by Atli; Jan 24 '08, 02:59 AM. Reason: Added [code] tags.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Originally posted by sandeepsandeep
      Hi,
      Fix the width of table and every column in numbering.
      [code=html]<table width="500"></table>
      <tr><td width="300"></td>
      <td width="200"></td>
      </tr>
      </table>[/code]

      so whenever first column data is exeed the width then it will be start from new line
      Hi.

      This will work 99% of the time, but if you have huge words, without spaces, most browsers will stretch the cell to fit the line.

      Like for example:
      [code=html]
      <table border="1">
      <tr>
      <td width="10">
      1234567890abcde fg...etc...
      </td>
      </tr>
      </table>
      [/code]
      If you try this HTML you will find that the cell far exceeds the 10px limit I set for it.

      If you run into this problem, you should check out the wordwrap PHP function.
      (Works well with fonts like 'Courier New')

      There is, unfortunately, no standard way to have the cell automatically wrap long words. We must resort to some sort of Javascript or server-side trickery to manage that.

      The closes standard way to handle situations like these is the CSS overflow property, but it's usefulness is extremely limited.

      P.S.
      sandeepsandeep, please put your code inside [code] tags, and don't just put it in bold. It's much more readable that way.

      Comment

      Working...